Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic Query Problem
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01518212
Message ID:
01518246
Vues:
44
>>Yes you didn't declare it :-)
>>The Dynamic SQL is executed in separate batch and any local variable declared in current batch is not visible there.
>>You must use sp_executesql:
>>
>>DECLARE @voter_id INT
>>SET @Command = 'SELECT @voter_id = voterid FROM tblCamp_CT WHERE VoterId = ' + CAST(@VoterId AS VARCHAR(20)) + ' AND ' + @Query
>>
>>EXEC sp_executesql @Command, N'@voter_id int OUTPUT', @voter_id = @voter_id OUTPUT
>>
>
>Ok, I tried this
>
>
>DECLARE @voter_id INT
>SET @Command = 'SELECT @voter_id = voterid FROM tblCamp_CT WHERE VoterId = ' + CAST(@VoterId AS VARCHAR(20)) + ' AND ' + @Query
>EXEC sp_executesql @Command, N'@voter_id int OUTPUT', @voter_id = @voter_id OUTPUT
>SELECT @voter_id
>
>
>and I'm now getting
>
>
>Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
>
>
>Not sure what @statement' is.

@Statement is your @Command. It should be declared as nvarchar(max) -- n is important here.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform