Reputation: 639
How to get number of rows with a SQL query?
I tried this :
SET @Records = count(*) SELECT * FROM [INVENTORY].[TBL_RECEIPTS]
WHERE Field_Tag = '1234'
But it is giving 1. What is wrong with the above code?
Actually there was no row, it should give the output 0
When I execute this
SELECT * FROM [INVENTORY].[TBL_RECEIPTS]
WHERE Field_Tag = '1234'
it is giving result 0
Upvotes: 0
Views: 742
Reputation: 26386
Do these - either should work, but I prefer the second code
SET @Records = (SELECT Count(*) FROM [INVENTORY].[TBL_RECEIPTS]
WHERE Field_Tag = '1234')
OR
SELECT @Records = Count(*) FROM [INVENTORY].[TBL_RECEIPTS]
WHERE Field_Tag = '1234'
Upvotes: 1
Reputation: 11058
Use
SET @Records = (SELECT count(*)
FROM [INVENTORY].[TBL_RECEIPTS]
WHERE Field_Tag = '1234')
Upvotes: 1
Reputation:
SELECT @Records = COUNT(*) FROM INVENTORY.TBL_RECEIPTS
WHERE Field_Tag = '1234';
Upvotes: 1