Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can not make query to work
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Can not make query to work
Divers
Thread ID:
00762448
Message ID:
00762448
Vues:
55
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform