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)
 Loop through table and check each variables

Author  Topic 

wongz
Starting Member

6 Posts

Posted - 2003-06-05 : 04:10:41
Hi,
I wanted to loop through my table and check each certain feild in each records so that i can call certain sp.E.g of my code:

Create Procedure spGetTodayAlert
As
Declare @id int
Declare @FK_UsersID int
Declare @isRepeatDaily bit
Declare @isRepeatOnDay tinyint
Declare @isRepeatOnDD tinyint
Declare @isRepeatOnMM tinyInt
SET DATEFIRST 1
Declare @day tinyInt
select @day= datepart(dw,getDate())

SELECT @id=id,
@FK_UsersID=FK_UsersID,
@isRepeatDaily=isRepeatDaily,
@isRepeatOnDay=isRepeatOnDay,
@isRepeatOnDD=isRepeatOnDD,
@isRepeatOnMM=isRepeatOnMM
FROM CalendarEvents
WHERE StartDateTime <=getDate() AND
EndDAteTime >=getDate()

If @isRepeatDaily=0
exec spRepeatdaily

If @isRepeatOnDay=1
exec spRepeatOnDay
Return 0
Go

i am very new in transact-sql and i know that the above code have problems because it didnt check 1 records.Thus i need help on anyone that is expert to guide me.THank you very much.

X002548
Not Just a Number

15586 Posts

Posted - 2003-06-05 : 09:50:08
quote:

Hi,
I am a student



Are you taking a class in SQL Server?

I'd get my money back...

First off the concept is wrong.. relational database are meant to do SET based process, you know like do everything at once. Not one at a time...(although we all know how prevelant the one at a time thingee is).

Second, it seems like your query will return MORE than 1 row. So you are trying to assign a SET (there that word again) to a single variable. In other rdbms's, this would fail (see DB2). But no not in SQL Sevrer baby.. I believe it's the last value of the set that gets assigned.

Third, you're calling stored procedures are probably taking some action. They should probablyu be incorporated in with the driver query that you've identified here...but I can't be sure.

Fourth, is this a homework assignment? What's your text book if it is? I'd start reading with, let's say, chapter 1. If it's not, pardon the sarcasim (ooohh a sarcasim detector...now that's a really useful device...)



Brett

8-)

Edited by - x002548 on 06/05/2003 11:13:07
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2003-06-05 : 09:55:26
What is this actually supposed to achieve? It all looks back to front to me.

-------
Moo.
Go to Top of Page
   

- Advertisement -