我正在尝试在 Visual Studio TableAdapter 查询向导中编写 SQL 查询
我的 SQL 查询是:
DECLARE @SQL varchar(255);
SET @SQL = ' SELECT * FROM dbAddress WHERE 1 = 1'
IF @ApexLine1 = ''
BEGIN
SET @SQL = @SQL + ' AND addLine1 IS NULL '
END
ELSE
BEGIN
SET @SQL = @SQL + ' AND addLine1 = ''' + @ApexLine1 + ''''
END
IF @ApexLine2 = ''
BEGIN
SET @SQL = @SQL + ' AND addLine2 IS NULL '
END
ELSE
BEGIN
SET @SQL = @SQL + ' AND addLine2 = ''' + @ApexLine2 + ''''
END
IF @ApexLine3 = ''
BEGIN
SET @SQL = @SQL + ' AND addLine3 IS NULL '
END
ELSE
BEGIN
SET @SQL = @SQL + ' AND addLine3 = ''' + @ApexLine3 + ''''
END
IF @ApexZip = ''
BEGIN
SET @SQL = @SQL + ' AND addPostCode IS NULL '
END
ELSE
BEGIN
SET @SQL = @SQL + ' AND addPostCode = ''' + @ApexZip + ''''
END
IF @ApexCity = ''
BEGIN
SET @SQL = @SQL + ' AND addLine4 IS NULL '
END
ELSE
BEGIN
SET @SQL = @SQL + ' AND addLine4 = ''' + @ApexCity + ''''
END
IF @ApexProv = ''
BEGIN
SET @SQL = @SQL + ' AND addLine5 IS NULL '
END
ELSE
BEGIN
SET @SQL = @SQL + ' AND addLine5 = ''' + @ApexProv + ''''
END
EXEC(@SQL)
我得到错误:
'不支持声明 SQL 结构或语句'
如果我删除 Declare 语句,我会收到错误:
'不支持 Set SQL 构造或语句'
有解决办法吗?
谢谢。