开发者

How to add dynamic SQL delimiter of single quote?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜