1
我已可以執行下面的腳本在SQL我怎樣才能顯示SQL字符串值的參數
Select Year as ' years between ' + @StartYear + '-' + @EndYear + ' value '
from tblYears
where Year Between @StartYear and @EndYear
我已可以執行下面的腳本在SQL我怎樣才能顯示SQL字符串值的參數
Select Year as ' years between ' + @StartYear + '-' + @EndYear + ' value '
from tblYears
where Year Between @StartYear and @EndYear
你有你的as
切換左右。這個名字來自最後
Select 'years between ' + @StartYear + '-' + @EndYear + ' value ' AS Year
from tblYears
where Year Between @StartYear and @EndYear
現在@StartYear和@EndYear也有可能不是CHAR/VARCHAR/NCHAR/nvarchar的,所以你需要將它們轉換。我將在這裏假設你的年份是一個4位整數。如果不是,你需要調整它。
Select 'years between ' + convert(char(4), @StartYear) + '-' + convert(char(4), @EndYear) + ' value ' AS Year
from tblYears
where Year Between @StartYear and @EndYear
我相信你想要的是這樣的,你在哪裏插入選定的行的值到最終的輸出?
SELECT CONVERT(CHAR(4), Year) + ' year is between '
+ CONVERT((CHAR(4),@StartYear) +'-'+ CONVERT((CHAR(4),@EndYear) + ' values.'
FROM tblYears
WHERE Year BETWEEN @StartYear AND @EndYear
否則,您甚至不需要FROM或WHERE,因爲您將一遍又一遍地打印相同的東西。然後,我會建議:
SELECT ' years between ' + CONVERT((CHAR(4),@StartYear) + '-'
+ CONVERT((CHAR(4),@EndYear) + ' value'
我相信'有'是錯字...它應該是'如何'。不是嗎?你能執行並看到你得到什麼錯誤? – 2012-03-08 15:21:30
應該是'[alias] ='或' AS [別名]'。不知道你在哪裏得到你正在使用的'[別名] AS '語法。 –
2012-03-08 15:40:11