将字符串附加到查询结果

时间:2013-12-02 10:56:42

标签: sql sql-server database string

我有一个场景,我想在数据库中提取的所有值的开头附加一个字符串'rajat'。查询看起来像

('rajat' + (SELECT a FROM b 
        WHERE b >= (SELECT TOP 1 c FROM d ORDER BY e DESC))) 

但这似乎不起作用。

2 个答案:

答案 0 :(得分:2)

SELECT a = 'rajat' + tableB.a
FROM dbo.b tableB
WHERE tableB.b >= (SELECT TOP 1 c FROM d ORDER BY e DESC)

答案 1 :(得分:0)

假设列a

的数据类型不同
SELECT 'rajat ' + cast(a as varchar(50)) as a
WHERE b >= (SELECT TOP 1 c FROM d ORDER BY e DESC)

如果列a是varchar,则简单直接。

SELECT 'rajat ' + a as a
WHERE b >= (SELECT TOP 1 c FROM d ORDER BY e DESC)