$ OPENQUERY SELECT语句内部

时间:2016-07-28 05:09:44

标签: sql-server

我的链接服务器查询工作正常。我需要做的就是在机架价格前打印一个美元符号($)。我该如何格式化?

SELECT * FROM OPENQUERY (TITAN_RICHARDSON, 'SELECT HotelName, RoomType, /*Print $ here*/ RoomRackRate FROM THAI_HOBS.dbo.Hotels H, THAI_HOBS.dbo.Rooms R WHERE H.HotelNo = R.HotelNo')

另外,如果我想做某种类型的数学运算(SUM,AVG)或CAST或CONVERT,我该如何做呢?

2 个答案:

答案 0 :(得分:0)

  SELECT HotelName, RoomType,     CONCAT ('$', RoomRackRate) FROM THAI_HOBS.dbo.Hotels H,     THAI_HOBS.dbo.Rooms R WHERE H.HotelNo = R.HotelNo;

总和

 SELECT HotelName, RoomType,     CONCAT ('$', SUM(RoomRackRate)) FROM THAI_HOBS.dbo.Hotels H,     THAI_HOBS.dbo.Rooms R WHERE H.HotelNo = R.HotelNo;

同样使用其他数学函数。

答案 1 :(得分:0)

 -- double quote the $ sign
 SELECT * 
 FROM OPENQUERY (TITAN_RICHARDSON, 
                 'SELECT  HotelName
                       ,  RoomType
                       ,  CONCAT (''$'', RoomRackRate)
                  FROM    THAI_HOBS.dbo.Hotels H
                       ,  THAI_HOBS.dbo.Rooms R 
                  WHERE   H.HotelNo = R.HotelNo'
                  );