Saving a select count(*) value to an integer (SQL Server)

后端 未结 4 484
失恋的感觉
失恋的感觉 2021-02-01 05:41

I\'m having some trouble with this statement, owing no doubt to my ignorance of what is returned from this select statement:

declare @myInt as INT
set @myInt = (         


        
4条回答
  •  时光说笑
    2021-02-01 06:05

    [update] -- Well, my own foolishness provides the answer to this one. As it turns out, I was deleting the records from myTable before running the select COUNT statement.

    How did I do that and not notice? Glad you asked. I've been testing a sql unit testing platform (tsqlunit, if you're interested) and as part of one of the tests I ran a truncate table statement, then the above. After the unit test is over everything is rolled back, and records are back in myTable. That's why I got a record count outside of my tests.

    Sorry everyone...thanks for your help.

提交回复
热议问题