rampuriyaaa
rampuriyaaa

Reputation: 5126

Append string to the query result

I have a scenario where I want to append a string 'rajat' at the beginning of all the values fetched from database. Query looks like

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

but this doesn't seems to work.

Upvotes: 1

Views: 9546

Answers (2)

Vishwanath Dalvi
Vishwanath Dalvi

Reputation: 36591

Assuming a different datatype for column a

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

simple and straight forward if column a is varchar.

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

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460048

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

Upvotes: 2

Related Questions