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)
 INSERT values when SELECT returns no rows

Author  Topic 

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-02-13 : 13:46:49
GReetings

I have a table variable
DECLARE @BranchWorkLoad TABLE(
[Date] [nvarchar](31) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DefinitionValue] [float] NOT NULL,
[DefinitionDate] [datetime] NOT NULL,
[Week] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)
When doing
INSERT INTO @BranchWorkLoad how can go ahead and insert values even if the SELECT returns no rows. force feed it :)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-13 : 13:49:31
What values would you like to insert if the SELECT doesn't return any rows?

INSERT INTO ...
SELECT ...

IF @@ROWCOUNT = 0
INSERT INTO ... VALUES(...)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 13:49:47
if select returns no values what values should you insert as default?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-13 : 13:51:21


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 13:53:58
quote:
Originally posted by tkizer



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



you're too fast
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-02-13 : 13:54:26
shoot me in the head..move my question to that list you guys keep of dumb questions ok time for coffee break. sorry about that stupid question....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 13:56:01
quote:
Originally posted by yosiasz

shoot me in the head..move my question to that list you guys keep of dumb questions ok time for coffee break. sorry about that stupid question....


no worries
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-13 : 13:57:08
It's not a stupid question!

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -