开发者

How to add dynamic SQL delimiter of single quote?

开发者 https://www.devze.com 2023-03-12 17:19 出处:网络
I am developing a dynamic SQL using SQL Server 2008 T-sql code.So I want to return values that look like \"Jan\'11\".

I am developing a dynamic SQL using SQL Server 2008 T-sql code. So I want to return values that look like "Jan'11".

My code looks something like:

left(datename(month, SGD_SIGNOFF_DATE), 3) + ' + '''' + ' RIGH开发者_运维问答T(year(SGD_SIGNOFF_DATE), 2) AS MonthYear

But this is not working. Either I get output to look like "Jan11" or I get error messages. What is proper syntax for my solution?


SELECT LEFT(datename(month, SGD_SIGNOFF_DATE), 3) + '''' + RIGHT(year(SGD_SIGNOFF_DATE), 2) AS MonthYear


This should work:

left(datename(month, SGD_SIGNOFF_DATE), 3) + '''' + RIGHT(year(SGD_SIGNOFF_DATE), 2) AS MonthYear


I got it! Here is the code now that works!

left(datename(month, SGD_SIGNOFF_DATE), 3) + '''''''' + RIGHT(year(SGD_SIGNOFF_DATE), 2) AS MonthYear

0

精彩评论

暂无评论...
验证码 换一张
取 消