Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Planet_x
Starting Member
15 Posts |
Posted - 2010-05-17 : 15:37:02
|
| Ok this is really aggravating.. I swear I have done this before using the exact same syntax and i cannot get it to work, keeps giving me invalid syntax error. How the hell do I declare an integer variable properly and set it equals to the count of my records in a table, is it not like the following?DECLARE @COUNTER INT(8)SET @COUNTER = SELECT COUNT(*) FROM dbo.TariffTemp |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2010-05-18 : 05:36:48
|
| What if in the table did dont exists any records? so:DECLARE @Counter INT;SELECT @Counter = COALESCE(SUM(1), 0) FROM table_name;Print @Counter______________________ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2010-05-18 : 15:58:52
|
| Oh you right, I was little mistake. I imagine MAX. Because if there are not records in the table SELECT MAX(i) FROM t will be NULL.For example:select isnull( (select max(id) from t), 1 )______________________ |
 |
|
|
|
|
|