Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic SQL - Incorrect syntax near '='. 1

Status
Not open for further replies.
Dec 28, 2004
87
US
Anyone can please help me out to solve this error

"Incorrect syntax near '='."


CREATE PROCEDURE [terrredesign].[P_Retrive_Dowload_data]
(@strWhere varchar(8000))AS
SET NOCOUNT ON
DECLARE @Error AS Integer

DECLARE @sql AS varchar(8000)
DECLARE @sql1 as varchar(8000)
DECLARE @sql2 as varchar(8000)

set @sql = " Select A.Cust_Life_Num, A.WLActCatId, A.WLDayId, A.WeekNo
from WLActCat_WLDay A Inner Join "

set sql1 = " (select distinct (cust_life_num) from CUSTTB where + @strWhere) B
On A.CustLifeNo = B.Cust_Life_num "

set sql2 = @sql + @ sql1

exec (@sql)
 
Couple things. First, SQL Server uses single quotes ' not double " to delimit strings.Second, it doesn't interpolate variables from within strings. "+ @strWhere" will be literally that.

In the end, print @sql before executing it and check the built string to see if it makes sense.

________________________________________
Andrew

I work for a gift card company!
 
set sql1 = ' (select distinct (cust_life_num) from CUSTTB where ' + @strWhere + ') B
On A.CustLifeNo = B.Cust_Life_num '


-------------------------
The trouble with doing something right the first time is that noboby appreciates how difficult it was.
- Steven Wright
 
Ah yes in addition, sql1 is not the variable @sql1 is. And this line , set sql2 = @sql + @ sql1, has two simliar typing errors.

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
Thanks for your reply but still i am getting an error...
let me paste my code...

" Incorrect syntax near '='." error occur on line set sql2

CREATE PROCEDURE [terrredesign].[P_Retrive_Dowload_data]
(@strWhere varchar(8000))AS
SET NOCOUNT ON
DECLARE @Error AS Integer

DECLARE @sql AS varchar(8000)
DECLARE @sql1 as varchar(8000)
DECLARE @sql2 as varchar(8000)

set @sql1 = 'Select A.Cust_Life_Num, A.WLActCatId, A.WLDayId, A.WeekNo
from WLActCat_WLDay A Inner Join '

set sql2 = ' (select distinct (cust_life_num) from CUSTTB where ' + @strWhere + ') B
On A.CustLifeNo = B.Cust_Life_num '

set sql = @sql1 + @ sql2

print @sql2

Go
 
oh...It was silly mistake i made...

I forgot to put @ at set sql2...

Oh....but anyway...i want say all of you thx a lot...

AD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top