Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using single talking marks (') with Dynamic SQL?

Author  Topic 

Darts75
Starting Member

27 Posts

Posted - 2014-10-29 : 23:52:16
Hi Everyone,

I am new to Dynamic SQL and have become quite stuck regarding how to included aliases which have spaces in my query. A related issue, which I believe also revolves around the use of single talking marks (') within Dynamic SQL is how to include argument values and variables in my queries.

From my limited research it 'feels like' what I need to do is the opposite of ESCAPE sequencing...

My issue is better explained through some code samples.

Each of the samples below assume the use of a variable within the overall query, e.g.: DECLARE @SQL nvarchar(max)

Here is a sample from a working query (excuse the brevity)



Now if I put a space into the Alias name as shown below the query will not run...



Similarly I am wondering how to go about assigning variables, within for example a WHERE clause?



Any help with the above broad questions will be greatly appreciated.

Kind Regards,

Davo

robvolk
Most Valuable Yak

15732 Posts

Posted - 2014-10-30 : 04:58:57
Duplicate of:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=196976
Go to Top of Page
   

- Advertisement -