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 2000 Forums
 Transact-SQL (2000)
 If in Where statement?

Author  Topic 

Rika1976
Starting Member

5 Posts

Posted - 2005-01-14 : 16:43:06
Okay, so heres the situation. About every hour I feed data from a que table into a larger database. Everyhour during business hours 25000 rows are loaded and after business hours, 50000 rows are loaded per hour, per run. This is deteremined by an if statement in a stored procedure before the SQL Query.


If Convert(char,getdate(),114) > '18:00:00:000'
BEGIN
SET ROWCOUNT 50000
END
ELSE
BEGIN
SET ROWCOUNT 25000
END

Now the issue is not only time, but what data goes in. I only want data loaded during the day that does not have 'Maint' in the field MU_PCIP.

The only thing I can think of is putting an If statement in the Where statement of the larger SQL query that actually selects all the fields to be uploaded. Is this even possible? Any suggestions would be great! Thanks.
Erika

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2005-01-14 : 16:58:55
How about something like:
declare @MU_PCIP varchar(5)

If Convert(char,getdate(),114) > '18:00:00:000'
BEGIN
SET ROWCOUNT 50000
SET @MU_PCIP = null
END
ELSE
BEGIN
SET ROWCOUNT 25000
SET @MU_PCIP = 'Maint'
END



INSERT <table>
SELECT <columns>
FROM <table>
WHERE
(@MU_PCIP IS NULL)
OR
(@MU_PCIP IS NOT NULL AND MU_PCIP != @MU_PCIP)
Go to Top of Page

Rika1976
Starting Member

5 Posts

Posted - 2005-01-14 : 17:19:27
Awesome!! That worked perfectly.
Thanks!!
Erika
Go to Top of Page
   

- Advertisement -