Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Interesting Query Problem
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01518190
Message ID:
01518202
Vues:
45
>>>Ok, I see what you're doing, excelt what's "Query"?
>>
>>Query is a field in the CompassQueries table.
>
>Ok, so I modified wht you posted...
>
>
>DECLARE @result varchar(max) 
>SELECT @result = coalesce(@result + ', ', '') + CompassQuery
>	FROM CompassQueries
>	WHERE CampaignId = 140
>
>declare @SQL nvarchar(max)
>SET @SQL = 'SELECT VoterID from tblCamp_CT WHERE ' + @result
>print @SQL
>--execute (@SQL)
>
>
>The @SQL variable now contains the following (a bit long)
>
>
>
>
>Notice at the end it's cut off. The string length is proably too long.
>
>Any other ideas? Any way to do with with a join?

Do you have more than 1 record in the CompassQuery that has CompaignID = 140?

Why you're not using what I posted - it should have lead to the correct query.

For your case try

>
>DECLARE @result nvarchar(max) 
>SET @Result = (select top (1) CompassQuery
>	FROM CompassQueries
>	WHERE CampaignId = 140)
>
>declare @SQL nvarchar(max)
>SET @SQL = 'SELECT VoterID from tblCamp_CT WHERE ' + @result
>print @SQL
>--execute (@SQL)
>
>
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform