 |
|
 |
|
Next: How to write this query? - 2
|
| Author |
Message |
External

Since: Apr 26, 2007 Posts: 5
|
(Msg. 1) Posted: Tue Oct 10, 2006 4:14 pm
Post subject: While loop? Archived from groups: microsoft>public>sqlserver>programming (more info?)
|
|
|
So I am just starting to learn how to use Database. I need the help of a SQL
guru! I have these three tables:
CREATE TABLE SB3_ScheduleChange
(
emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY KEY,
Monday char(35) NULL,
Tuesday char(35) NULL,
Wednesday char(35) NULL,
Thursday char(35) NULL,
Friday char(35) NULL,
Saturday char(35) NULL,
Sunday char(35) NULL,
Name char(35) NOT NULL;
)
CREATE TABLE SB3_ScheduleChange
(
emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY KEY,
sched_type_id nt, NOT NULL,
start_date DateType:datetime NOT NULL,
end_date DateType:datetime NOT NULL,
comments varchar(8000) NULL,
)
CREATE TABLE SB3_ScheduleType
(
sched_type_id int, NOT NULL PRIMARY KEY,
reason char(20) NULL,
)
I am trying to come up with a query that will iterate through each employee
with the emp_num primary key in the emp_shcedule table. I would like the
iteration to check if the employee has an exception or "change" from their
regular default schedule in the table emp_schedule checking it against the
"SB3_ScheduleChange" table. And if the query finds a difference in schedule
to update or insert it into that employees default schedule until the change
is over on a certain date. My problem is I am new to SQL and I dont know how
to do this. Do I need a Calendar table? Use a while loop? Any examples,
help, or suggestions would be very much appreciated. Not that this will help
but here are some queries I have come up with. Just dont know how to tie it
all together.
This would list name, emp_num, sched_type_id, for each employee who has
A schedule type difference. Query shows every employee with a schedule type
difference.
SELECT es.Name, es.emp_num, sc.sched_type_id
FROM emp_schedule AS es JOIN SB3_ScheduleChange AS sc
ON(es.emp_num = sc.emp_num)
List name, emp_num of employees that are not assigned to any schedule
change. Query shows every employee without a schedule type difference.
SELECT name, emp_num
FROM emp_schedule AS es
WHERE NOT EXISTS
(SELECT emp_num
FROM SB3_ScheduleChange AS sc
WHERE es.emp_num = sc.emp_num);
And if necessary a Calendar CREATE TABLE. But once again I am not sure.
CREATE TABLE dbo.SB3_Calender
(
ActualDate DATETIME NOT NULL PRIMARY KEY,
MonthName CHAR(15) NULL,
DayNumber INT NULL,
YearNumber INT NULL,
DayOfWeek CHAR(15) NULL
CHECK (DayOfWeek IN ('Sunday', 'Monday', 'Tuesday',
'Wednesday','Thursday','Friday','Saturday')),
DayType CHAR(15) NULL
CHECK ( DayType IN ('Business','Weekend','Holiday')),
)
GO
SET NOCOUNT ON
DECLARE @Counter INT
DECLARE @ActualDate DATETIME
DECLARE @FirstDate DATETIME
SET @Counter = 1
SET @FirstDate = '1/1/2006'
SET @ActualDate = @FirstDate
WHILE @Counter < 1096
BEGIN
INSERT INTO Calender (ActualDate)
values(@ActualDate)
SET @ActualDate = DATEADD(day, @Counter, @FirstDate)
SET @Coutner = @Counter + 1
END
GO
UPDATE Calender
SET DayOfWeek = DateName(DW, ActualDate)
GO
UPDATE Calender
SET DayNumber = DateName(DD,ActualDate)
GO
UPDATE Calender
SET MonthName = DateName(MM,ActualDate)
GO
UPDATE Calender
SET YearNumber = DateName(YY,ActualDate)
GO
UPDATE Calender
SET DayType = 'Business'
WHERE DayOfWeek <> 'Saturday' AND DayOfWeek <> 'Sunday'
GO
UPDATE Calender
SET DayType = 'Weekend'
WHERE DayOfWeek = 'Saturday' OR DayOfWeek = 'Sunday'
GO
UPDATE Calender
SET DayType = 'Holiday'
WHERE (MonthName ='January' AND DayNumber = 1 ) OR
(MonthName ='July' AND DayNumber = 4) OR
(MonthName ='December' AND DayNumber = 25)
GO
Thank you in advance! >> Stay informed about: While loop? |
|
| Back to top |
|
 |  |
External

Since: Oct 08, 2006 Posts: 9
|
(Msg. 2) Posted: Tue Oct 10, 2006 5:12 pm
Post subject: Re: While loop? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Apr 26, 2007 Posts: 5
|
(Msg. 3) Posted: Wed Oct 11, 2006 10:00 am
Post subject: RE: While loop? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Ok, SO I have this table that produces a default schedule for employees:
CREATE TABLE emp_schedule
(
emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY KEY,
Monday char(35) NULL,
Tuesday char(35) NULL,
Wednesday char(35) NULL,
Thursday char(35) NULL,
Friday char(35) NULL,
Saturday char(35) NULL,
Sunday char(35) NULL,
Name char(35) NOT NULL;
)
This is the Query Web page currently uses:
-----------------------------------------
SELECT Name, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
FROM emp_schedule
This is the resulting data that shows in an intranet datagrid:
Name Monday Tuesday
--------------- ------------- ---------------------
smith,John Normal Normal
Lantern, Bret 7:30-4:30 7:30-4:30
Clause, Santa 8-4 8-4
Diego, Jaun 8 AM - 4:30 PM 7:30 AM - 4 PM
Duck, Donald normal normal
I would like to come up with a query that will iterate through each employee
with the emp_num primary key in the emp_shcedule table. I would like the
iteration to check if the employee has an exception or "change" from their
regular default schedule in the table emp_schedule table checking it against
the "SB3_ScheduleChange" table.
And if the query finds a difference in schedule to update or insert it into
that
employees default schedule with the SB3_ScheduleType until the change is
over on a certain date.
Other tables:
--------------
CREATE TABLE SB3_ScheduleChange
(
emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY KEY,
sched_type_id nt, NOT NULL,
start_date DateType:datetime NOT NULL,
end_date DateType:datetime NOT NULL,
comments varchar(8000) NULL,
)
CREATE TABLE SB3_ScheduleType
(
sched_type_id int, NOT NULL PRIMARY KEY,
reason char(20) NULL,
)
Query to show employees with schedule differences:
-------------------------------------------------
SELECT es.Name, es.emp_num, sc.sched_type_id
FROM emp_schedule AS es JOIN SB3_ScheduleChange AS sc
ON(es.emp_num = sc.emp_num)
Result:
Name emp_num sched_type_id
----------------------------------- ------- -------------
Smith,John 1 Vacation
JackOLantern 2 Sick
So I would like to create some query that would take this resulting data
and put "Vacation" or "sick" into the days the employee is on vacation or
sick in the datagrid.
Desired result:
----------------
Name Monday Tuesday
--------------- ------------- ---------------------
smith,John Vacation Vacation
Lantern, Bret Sick Sick
Clause, Santa 8-4 8-4
Diego, Jaun 8 AM - 4:30 PM 7:30 AM - 4 PM
Duck, Donald normal normal
I hope that is enough information to give me any kind of help or examples on
how
to do this. Thank you for helping me in advance, very appreciated.
"ML" wrote:
> If you could post some sample data and expected results, I believe we can
> show you how to avoid cursors and come up with a st-based solution.
>
>
> ML
>
> ---
> http://milambda.blogspot.com/ >> Stay informed about: While loop? |
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 210
|
(Msg. 4) Posted: Wed Oct 11, 2006 11:22 am
Post subject: Re: While loop? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Here is an example:
However, even though I'm telling you how to do it, CURSORs should be avoided
if they can be (yes, a blanket statement).
They don't perform very well.
I've written exactly 1 cursor since 2001.....................
Anyway, here you go. The "double" part isn't necessary, but its good to
know.
Use Northwind
GO
declare @PROC_fetch_status int
declare @CustomerID varchar(12)
declare @ContactName varchar(24)
declare @OrderID int
declare @OrderDate datetime
-- Select * from Customers
DECLARE curCustomers CURSOR FAST_FORWARD FOR select CustomerID , ContactName
from Customers Order by ContactName
OPEN curCustomers
-- Perform the first fetch.
fetch curCustomers into @CustomerID , @ContactName
select @PROC_fetch_status = @@fetch_status
IF @PROC_fetch_status <> 0
begin
print 'No Records'
end
WHILE @PROC_fetch_status = 0
BEGIN
print 'Current Customer = ' + @CustomerID + ' : ' + @ContactName
print '------------------------------------'
declare curOrders cursor FAST_FORWARD for select OrderID , OrderDate
from Orders where CustomerID = @CustomerID
OPEN curOrders
-- Perform the first fetch.
fetch curOrders into @OrderID , @OrderDate
WHILE @@FETCH_STATUS = 0
BEGIN
print convert(varchar(32) , @OrderID ) + ' ' + convert(varchar(32) ,
@OrderDate )
FETCH NEXT FROM curOrders INTO @OrderID , @OrderDate
END
CLOSE curOrders
DEALLOCATE curOrders
print ''
print ''
print ''
FETCH NEXT FROM curCustomers INTO @CustomerID , @ContactName
select @PROC_fetch_status = @@fetch_status
END
CLOSE curCustomers
DEALLOCATE curCustomers
"Dirk" wrote in message
> So I am just starting to learn how to use Database. I need the help of a
SQL
> guru! I have these three tables:
> CREATE TABLE SB3_ScheduleChange
> (
> emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY KEY,
> Monday char(35) NULL,
> Tuesday char(35) NULL,
> Wednesday char(35) NULL,
> Thursday char(35) NULL,
> Friday char(35) NULL,
> Saturday char(35) NULL,
> Sunday char(35) NULL,
> Name char(35) NOT NULL;
> )
>
>
> CREATE TABLE SB3_ScheduleChange
> (
> emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY
KEY,
> sched_type_id nt, NOT NULL,
> start_date DateType:datetime NOT NULL,
> end_date DateType:datetime NOT NULL,
> comments varchar(8000) NULL,
> )
>
> CREATE TABLE SB3_ScheduleType
> (
> sched_type_id int, NOT NULL PRIMARY KEY,
> reason char(20) NULL,
>
> )
>
> I am trying to come up with a query that will iterate through each
employee
> with the emp_num primary key in the emp_shcedule table. I would like the
> iteration to check if the employee has an exception or "change" from their
> regular default schedule in the table emp_schedule checking it against the
> "SB3_ScheduleChange" table. And if the query finds a difference in
schedule
> to update or insert it into that employees default schedule until the
change
> is over on a certain date. My problem is I am new to SQL and I dont know
how
> to do this. Do I need a Calendar table? Use a while loop? Any examples,
> help, or suggestions would be very much appreciated. Not that this will
help
> but here are some queries I have come up with. Just dont know how to tie
it
> all together.
>
> This would list name, emp_num, sched_type_id, for each employee who has
> A schedule type difference. Query shows every employee with a schedule
type
> difference.
>
> SELECT es.Name, es.emp_num, sc.sched_type_id
> FROM emp_schedule AS es JOIN SB3_ScheduleChange AS sc
> ON(es.emp_num = sc.emp_num)
>
>
> List name, emp_num of employees that are not assigned to any schedule
> change. Query shows every employee without a schedule type difference.
>
> SELECT name, emp_num
> FROM emp_schedule AS es
> WHERE NOT EXISTS
> (SELECT emp_num
> FROM SB3_ScheduleChange AS sc
> WHERE es.emp_num = sc.emp_num);
>
> And if necessary a Calendar CREATE TABLE. But once again I am not sure.
> CREATE TABLE dbo.SB3_Calender
> (
> ActualDate DATETIME NOT NULL PRIMARY KEY,
> MonthName CHAR(15) NULL,
> DayNumber INT NULL,
> YearNumber INT NULL,
> DayOfWeek CHAR(15) NULL
> CHECK (DayOfWeek IN ('Sunday', 'Monday', 'Tuesday',
> 'Wednesday','Thursday','Friday','Saturday')),
> DayType CHAR(15) NULL
> CHECK ( DayType IN ('Business','Weekend','Holiday')),
> )
>
> GO
>
> SET NOCOUNT ON
> DECLARE @Counter INT
> DECLARE @ActualDate DATETIME
> DECLARE @FirstDate DATETIME
> SET @Counter = 1
> SET @FirstDate = '1/1/2006'
> SET @ActualDate = @FirstDate
> WHILE @Counter < 1096
> BEGIN
> INSERT INTO Calender (ActualDate)
> values(@ActualDate)
> SET @ActualDate = DATEADD(day, @Counter, @FirstDate)
> SET @Coutner = @Counter + 1
> END
>
> GO
>
> UPDATE Calender
> SET DayOfWeek = DateName(DW, ActualDate)
>
> GO
>
> UPDATE Calender
> SET DayNumber = DateName(DD,ActualDate)
>
> GO
>
> UPDATE Calender
> SET MonthName = DateName(MM,ActualDate)
>
> GO
>
> UPDATE Calender
> SET YearNumber = DateName(YY,ActualDate)
>
> GO
>
> UPDATE Calender
> SET DayType = 'Business'
> WHERE DayOfWeek <> 'Saturday' AND DayOfWeek <> 'Sunday'
>
> GO
>
> UPDATE Calender
> SET DayType = 'Weekend'
> WHERE DayOfWeek = 'Saturday' OR DayOfWeek = 'Sunday'
>
> GO
>
> UPDATE Calender
> SET DayType = 'Holiday'
> WHERE (MonthName ='January' AND DayNumber = 1 ) OR
> (MonthName ='July' AND DayNumber = 4) OR
> (MonthName ='December' AND DayNumber = 25)
>
> GO
>
> Thank you in advance! >> Stay informed about: While loop? |
|
| Back to top |
|
 |  |
External

Since: Apr 26, 2007 Posts: 5
|
(Msg. 5) Posted: Wed Oct 11, 2006 11:22 am
Post subject: Re: While loop? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Great, I appreciate the info. I will read up on cursors and the examples
given to me and see what I can come up with. Then go from there. Unless
you have any other suggestions.
"sloan" wrote:
> Here is an example:
>
> However, even though I'm telling you how to do it, CURSORs should be avoided
> if they can be (yes, a blanket statement).
> They don't perform very well.
>
> I've written exactly 1 cursor since 2001.....................
>
> Anyway, here you go. The "double" part isn't necessary, but its good to
> know.
>
>
>
> Use Northwind
>
>
> GO
>
>
> declare @PROC_fetch_status int
>
>
> declare @CustomerID varchar(12)
> declare @ContactName varchar(24)
>
>
> declare @OrderID int
> declare @OrderDate datetime
>
>
> -- Select * from Customers
> DECLARE curCustomers CURSOR FAST_FORWARD FOR select CustomerID , ContactName
> from Customers Order by ContactName
> OPEN curCustomers
>
>
> -- Perform the first fetch.
> fetch curCustomers into @CustomerID , @ContactName
>
>
> select @PROC_fetch_status = @@fetch_status
>
>
> IF @PROC_fetch_status <> 0
> begin
> print 'No Records'
> end
>
>
> WHILE @PROC_fetch_status = 0
> BEGIN
>
>
> print 'Current Customer = ' + @CustomerID + ' : ' + @ContactName
> print '------------------------------------'
>
>
> declare curOrders cursor FAST_FORWARD for select OrderID , OrderDate
> from Orders where CustomerID = @CustomerID
> OPEN curOrders
>
>
> -- Perform the first fetch.
> fetch curOrders into @OrderID , @OrderDate
>
>
> WHILE @@FETCH_STATUS = 0
> BEGIN
>
>
> print convert(varchar(32) , @OrderID ) + ' ' + convert(varchar(32) ,
> @OrderDate )
>
>
> FETCH NEXT FROM curOrders INTO @OrderID , @OrderDate
> END
> CLOSE curOrders
> DEALLOCATE curOrders
>
>
> print ''
> print ''
> print ''
>
>
> FETCH NEXT FROM curCustomers INTO @CustomerID , @ContactName
> select @PROC_fetch_status = @@fetch_status
>
>
> END
> CLOSE curCustomers
> DEALLOCATE curCustomers
>
>
>
>
>
>
>
>
>
>
>
>
> "Dirk" wrote in message
>
> > So I am just starting to learn how to use Database. I need the help of a
> SQL
> > guru! I have these three tables:
> > CREATE TABLE SB3_ScheduleChange
> > (
> > emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY KEY,
> > Monday char(35) NULL,
> > Tuesday char(35) NULL,
> > Wednesday char(35) NULL,
> > Thursday char(35) NULL,
> > Friday char(35) NULL,
> > Saturday char(35) NULL,
> > Sunday char(35) NULL,
> > Name char(35) NOT NULL;
> > )
> >
> >
> > CREATE TABLE SB3_ScheduleChange
> > (
> > emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY
> KEY,
> > sched_type_id nt, NOT NULL,
> > start_date DateType:datetime NOT NULL,
> > end_date DateType:datetime NOT NULL,
> > comments varchar(8000) NULL,
> > )
> >
> > CREATE TABLE SB3_ScheduleType
> > (
> > sched_type_id int, NOT NULL PRIMARY KEY,
> > reason char(20) NULL,
> >
> > )
> >
> > I am trying to come up with a query that will iterate through each
> employee
> > with the emp_num primary key in the emp_shcedule table. I would like the
> > iteration to check if the employee has an exception or "change" from their
> > regular default schedule in the table emp_schedule checking it against the
> > "SB3_ScheduleChange" table. And if the query finds a difference in
> schedule
> > to update or insert it into that employees default schedule until the
> change
> > is over on a certain date. My problem is I am new to SQL and I dont know
> how
> > to do this. Do I need a Calendar table? Use a while loop? Any examples,
> > help, or suggestions would be very much appreciated. Not that this will
> help
> > but here are some queries I have come up with. Just dont know how to tie
> it
> > all together.
> >
> > This would list name, emp_num, sched_type_id, for each employee who has
> > A schedule type difference. Query shows every employee with a schedule
> type
> > difference.
> >
> > SELECT es.Name, es.emp_num, sc.sched_type_id
> > FROM emp_schedule AS es JOIN SB3_ScheduleChange AS sc
> > ON(es.emp_num = sc.emp_num)
> >
> >
> > List name, emp_num of employees that are not assigned to any schedule
> > change. Query shows every employee without a schedule type difference.
> >
> > SELECT name, emp_num
> > FROM emp_schedule AS es
> > WHERE NOT EXISTS
> > (SELECT emp_num
> > FROM SB3_ScheduleChange AS sc
> > WHERE es.emp_num = sc.emp_num);
> >
> > And if necessary a Calendar CREATE TABLE. But once again I am not sure.
> > CREATE TABLE dbo.SB3_Calender
> > (
> > ActualDate DATETIME NOT NULL PRIMARY KEY,
> > MonthName CHAR(15) NULL,
> > DayNumber INT NULL,
> > YearNumber INT NULL,
> > DayOfWeek CHAR(15) NULL
> > CHECK (DayOfWeek IN ('Sunday', 'Monday', 'Tuesday',
> > 'Wednesday','Thursday','Friday','Saturday')),
> > DayType CHAR(15) NULL
> > CHECK ( DayType IN ('Business','Weekend','Holiday')),
> > )
> >
> > GO
> >
> > SET NOCOUNT ON
> > DECLARE @Counter INT
> > DECLARE @ActualDate DATETIME
> > DECLARE @FirstDate DATETIME
> > SET @Counter = 1
> > SET @FirstDate = '1/1/2006'
> > SET @ActualDate = @FirstDate
> > WHILE @Counter < 1096
> > BEGIN
> > INSERT INTO Calender (ActualDate)
> > values(@ActualDate)
> > SET @ActualDate = DATEADD(day, @Counter, @FirstDate)
> > SET @Coutner = @Counter + 1
> > END
> >
> > GO
> >
> > UPDATE Calender
> > SET DayOfWeek = DateName(DW, ActualDate)
> >
> > GO
> >
> > UPDATE Calender
> > SET DayNumber = DateName(DD,ActualDate)
> >
> > GO
> >
> > UPDATE Calender
> > SET MonthName = DateName(MM,ActualDate)
> >
> > GO
> >
> > UPDATE Calender
> > SET YearNumber = DateName(YY,ActualDate)
> >
> > GO
> >
> > UPDATE Calender
> > SET DayType = 'Business'
> > WHERE DayOfWeek <> 'Saturday' AND DayOfWeek <> 'Sunday'
> >
> > GO
> >
> > UPDATE Calender
> > SET DayType = 'Weekend'
> > WHERE DayOfWeek = 'Saturday' OR DayOfWeek = 'Sunday'
> >
> > GO
> >
> > UPDATE Calender
> > SET DayType = 'Holiday'
> > WHERE (MonthName ='January' AND DayNumber = 1 ) OR
> > (MonthName ='July' AND DayNumber = 4) OR
> > (MonthName ='December' AND DayNumber = 25)
> >
> > GO
> >
> > Thank you in advance!
>
>
> >> Stay informed about: While loop? |
|
| Back to top |
|
 |  |
External

Since: Dec 07, 2004 Posts: 300
|
(Msg. 6) Posted: Thu Oct 12, 2006 7:02 am
Post subject: Re: While loop? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
>> So I am just starting to learn how to use Database. <<
1) What you are doing is mimicing a paper schedule form, not designing
a normalized schema.
2) data element names like the days of the week are values and not
attributes. Tha tis the output of a cross tabs report, not a table.
3) Column names like "sched_type_id" are absurd; an attribute can a key
(identifier, points to a unique *entity* in the data model) or a type
(non-key *attribute*, holds a value) but NEVER both.
4) You are still thinking about procedural code instead of declarative
programming and data. YOu have designed a magentic tape file merge,
complete with record at a time processing. Welcom to 1957!
Why not something like this?
CREATE TABLE PersonnelSchedules
(emp_num CHAR(7) NOT NULL
REFERENCES Personnel(emp_num)
ON UPDATE CASCADE
ON DELETE CASCADE,
activity_date DATETIME NOT NULL,
PRIMARY KEY (emp_num, activity_date),
activity_code INTEGER NOT NULL
CHECK (activity_code IN (...)),
..); ,
I am assuming one activity per day; if not this can be modified by
adding an activity number. You might need other attributes, but I
don't know you business rules. A single fact should be modeled witha
single row in a single table, not split all over the schema.
>> I am trying to come up with a query that will iterate through each employee with the emp_num primary key in the emp_shcedule table. I would like the iteration to check if the employee has an exception or "change" from their regular default schedule in the table emp_schedule checking it against the "SB3_ScheduleChange" table. <<
Why not go to the PersonnelSchedules and make this change, without
storing it in multiple locations? If you need to mark something as a
schedule change, then add a column for that attribute to the table.
When you get a new guy, fill out his schedule for 5-10 years in
advance. It will use less disk space than a hi-res employee badge
photograph. Now you can use a VIEW to get the weekly schedules, you
can do manpower projections, etc.
Most queries are easy if you have the right DDL. You should never use
a cursor in your SQL; we had to in the old days because we did not have
CTEs, CASE expressions, etc. >> Stay informed about: While loop? |
|
| Back to top |
|
 |  |
| Related Topics: | How to loop through records - I have @WeekIDFrom and @WeekIDTo as input parameters in a stored procedure. I need to loop through each value between @WeekIDFrom and @WeekIDTo and insert the value into a table, like this: INSERT INTO tblSchedule (WeekID) VALUES (@WeekID) Can someone...
How to loop a temp table? - I have a statement in my stored procedure that has the following as an example - INSERT #TempTableOutput EXEC (@select + @from + @where + @order) How could I then loop through the records of #TempTableOutput to update some blank fields that were..
Loop through Table Records - I'm working on a script that creates a temp table called #tmpList. How can Loop through the records of #tmpList? So far in my using SQL, I've always written SQL statements to just return records and I did my looping with VB. I need to be able to loop....
Date and case loop - My date work but I need to put it in a case loop, can anyone help me. Declare @DayOfWeek int Declare @dayname varchar(10) set @DayOfWeek = datepart(dw, getdate()) case When @DayOfWeek = 1 Then @dayname ='Sunday' When @DayOfWeek = 2 Then @dayname..
loop through all table names in all db's - I need to loop through all table names in all db's, but I can't get it to work. Pseudo code: Fetch dbname into @db while (@db) ( Fetch table names in @db..sysobjects into @table while (@table) ( Fetch table names in @db..sysobjects int... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|