我在我的數據庫中有這個字段year_start_1
它是一個整數字段,輸出示例是20100827
我試圖創建一個子字符串來創建年份,星期,天和更改格式是27/08/2010
ASP.NET查詢子字符串
這裏就是我想要
Dim query as String = "Select * from openquery (devbook, 'SELECT cast(year_start_1 as varchar(8)) as year_start_1, DATENAME(DAY, substring(CAST(year_start_1 AS VARCHAR(8)),6,2) + DATENAME(MONTH, substring(CAST(year_start_1 AS VARCHAR(8)),4,2) + DATENAME(YEAR, substring(CAST(year_start_1 AS VARCHAR(8)),1,4))) FROM web_statements')"
它只是扔了一個錯誤,我不知道爲什麼:
服務器無法處理reques t
我試過使用轉換,但它不起作用。
任何想法?
UPDATE
與克里斯的建議
Dim query as String = "Select * from openquery (devbook, 'SELECT year_start_1, cast(year_start_1 as varchar(8)) as year_start_1, substring(CAST(year_start_1 AS VARCHAR(8)),7,2)+''/''+substring(CAST(year_start_1 AS VARCHAR(8)),5,2)+''/''+substring(CAST(year_start_1 AS VARCHAR(8)),1,4) FROM web_statements')"
仍然得到錯誤
感謝
UPDATE
可能似乎無法得到它內部的工作曲ERY所以不得不在ASP.Net代碼周圍做一個工作
'POINTS END DATE YEAR
Dim strPointsDateEndYear = Mid(drv.Row("year_end_1"), 3, 2)
Dim strPointsDateEndMonth = Mid(drv.Row("year_end_1"), 5,2)
Dim strPointsDateEndDay = Right(drv.Row("year_end_1"), 2)
Dim strPointsDateEnd As String = strPointsDateEndDay + "/" + strPointsDateEndMonth + "/" + strPointsDateEndYear
感謝您的幫助,雖然
@InSane剛剛在T-SQL中得到一個'服務器無法處理請求'的錯誤 – 2010-10-06 10:41:53
,+確實作爲串聯工作。 – Nellius 2010-10-06 10:54:20
@InSane:T-SQL中的字符串連接操作符是'+','&'是一個數字操作符。 – Guffa 2010-10-06 10:55:03