0

如何使用 SQL 查询获取行数?

我试过这个:

SET @Records = count(*) SELECT * FROM  [INVENTORY].[TBL_RECEIPTS] 
                WHERE Field_Tag = '1234'

但它给出了 1. 上面的代码有什么问题?

实际上没有行,它应该给输出 0

当我执行这个

SELECT * FROM  [INVENTORY].[TBL_RECEIPTS] 
WHERE Field_Tag = '1234'

它给出了结果 0

4

3 回答 3

1

采用

SET @Records = (SELECT count(*)
                  FROM [INVENTORY].[TBL_RECEIPTS]
                 WHERE Field_Tag = '1234')
于 2013-04-04T23:09:47.410 回答
1
SELECT @Records = COUNT(*) FROM INVENTORY.TBL_RECEIPTS
   WHERE Field_Tag = '1234';
于 2013-04-04T23:15:14.260 回答
1

做这些 - 任何一个都应该工作,但我更喜欢第二个代码

SET @Records = (SELECT Count(*) FROM  [INVENTORY].[TBL_RECEIPTS] 
                WHERE Field_Tag = '1234')

或者

SELECT @Records = Count(*) FROM  [INVENTORY].[TBL_RECEIPTS] 
                WHERE Field_Tag = '1234'
于 2013-04-04T23:16:20.203 回答