user3010406
user3010406

Reputation: 579

Adding A String Literal To SQL Results

I have a SQL query similar to the below:

SELECT COUNT(*) TheseMatch, 
(SELECT COUNT(*) FROM [MyTable]) ThisIsMyTotal
FROM [MyTable]  
WHERE MyCondition = 'MyCondition'

I am trying to add a string literal to this, that will be available on the same returned row. I have been trying this:

SELECT 'THIS IS MY STRING' as Note,
SELECT COUNT(*) TheseMatch, 
(SELECT COUNT(*) FROM [MyTable]) ThisIsMyTotal
FROM [MyTable]  
WHERE MyCondition = 'MyCondition'

However this returns a syntax error. What would be the proper way to explicitly specify a string literal, and add it to the results?

TIA!

Upvotes: 1

Views: 2771

Answers (2)

nshah
nshah

Reputation: 340

SELECT 'THIS IS MY STRING' as Note,   
SELECT COUNT(*) TheseMatch, 
(SELECT COUNT(*) FROM Banks) ThisIsMyTotal
FROM Banks  
WHERE Banks.Name = 'MyCondition'

Upvotes: 0

user2989408
user2989408

Reputation: 3137

The right syntax would be something like

SELECT 'THIS IS MY STRING' as Note,
     COUNT(*) TheseMatch, 
     (SELECT COUNT(*) FROM [MyTable]) ThisIsMyTotal
FROM [MyTable]  
WHERE MyCondition = 'MyCondition'

Upvotes: 3

Related Questions