Advertisement

06.12.2008 at 02:08PM PDT, ID: 23481114
[x]
Attachment Details

concat in dynamic sql

Asked by jung1975 in MS SQL Server, SQL Server 2005

How can I concat string in dynamic sql?
I need to put the below SQL in Dynamic sql
Select ID ,Question, answer, (question + ':' +  answer) as Question_Text from table
where question = @question


I've tried somthing like below but i keep getting an error?
Declare @sql varchar(max)


set @sql = 'Select ID ,Question, answer, (question + ''':''' + answer) as Question_Text from table  where question = ' + @Question + ''
Exec @sqlStart Free Trial
[+][-]06.12.2008 at 02:12PM PDT, ID: 21773762

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.12.2008 at 02:14PM PDT, ID: 21773776

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.12.2008 at 02:16PM PDT, ID: 21773792

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Server 2005
Sign Up Now!
Solution Provided By: i2mental
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.12.2008 at 03:26PM PDT, ID: 21774213

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628