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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to update a table having zero records

Author  Topic 

vision.v1
Yak Posting Veteran

72 Posts

Posted - 2009-09-02 : 08:18:23
Hi,

In my application am having table

select * from ctlServiceLevel
displays some times 1 record or 0 record

i dont want to use insert statement...

UPDATE
ctlServiceLevel
SET
DATABASENAME = 'COMMON',
DATE = '09/01/2009',
LASTSL = 87.88

i want to update a table when the table contains 0 records or it contains records

how to achieve this please suggest me........









madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-02 : 08:32:47
Then when do you want to insert?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

vision.v1
Yak Posting Veteran

72 Posts

Posted - 2009-09-02 : 08:43:48
quote:
Originally posted by madhivanan

Then when do you want to insert?

Madhivanan

Failing to plan is Planning to fail



Irrespective of the data present in the table or not, i want to execute the above update statement..

Is it possible??

thanks for reply
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-02 : 08:50:51
quote:
Originally posted by vision.v1

quote:
Originally posted by madhivanan

Then when do you want to insert?

Madhivanan

Failing to plan is Planning to fail



Irrespective of the data present in the table or not, i want to execute the above update statement..

Is it possible??

thanks for reply


if there's no records, then what will you update? or do you want to insert in that case?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-02 : 08:54:53
if yes, this is what you want


UPDATE
ctlServiceLevel
SET
DATABASENAME = 'COMMON',
DATE = '09/01/2009',
LASTSL = 87.88

IF @@ROWCOUNT=0
BEGIN
INSERT INTO ctlServiceLevel(DATABASENAME,DATE ,LASTSL)
VALUES ('COMMON','09/01/2009',87.88 )
END


Go to Top of Page
   

- Advertisement -