Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can not make query to work
Message
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Can not make query to work
Miscellaneous
Thread ID:
00762448
Message ID:
00762448
Views:
56
Hi everybody,

Here is what I'm trying to do:
declare @Sql varchar(1000), @tnCartID int, @Category char(1), @Temp char(1000)
set @Temp = 'select CredID, State, Address from Credit..CreditInfo where CredID in ' +
     '(select CredID from CartDetail inner Join CartContent on 
        CartDetail.CartContentID = CartContent.CartContentID and CartContent.CartID = 4' +
      ' and CartContent.CreditCategory = '
set @tnCartID = 4
set @Category = 'L'

SET @Sql = @Temp + quotename(@Category,char(34)) +')'

execute (@Sql)
Returns incorrect syntax near '='

I can not make it work. I tried different combinations and the only working is
SET @Sql =  'select CredID, State, Address from Credit..CreditInfo where CredID in ' +
     '(select CredID from CartDetail inner Join CartContent on 
        CartDetail.CartContentID = CartContent.CartContentID and CartContent.CartID = 4' +
      ' and CartContent.CreditCategory = ''' + @Category +''')'

execute (@Sql)
Also how can I reference result of select within procedure, e.g.
select ...

select .. from prev. select
?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform