Reputation: 579
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
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
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