Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting Query Problem
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01518190
Message ID:
01518202
Views:
44
>>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform