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)
 help insert employee to #temp table all month

Author  Topic 

midan1
Starting Member

39 Posts

Posted - 2008-01-05 : 20:20:58
help insert employees to #temp table all month
and loop insert until the last employee

i have table employee

empid name
--------------------
1111 xxxx
2222 yyyy
-----------------------
now i need to insert all the employee for all month to one table
like this


insert empid=1111
to tb_temp
start day=01/02/2008
end day = 11/02/2008
val=1
NEXT
insert empid=2222
to tb_temp
start day=05/02/2008
end day = 20/02/2008
val=5
NEXT
....


and after i need to get the employee in the temp_table
BUT WITH condition
and only on Saturday + Sunday

i need to change the val !


if 'Saturday'
than val=55
if 'Sunday'
than val=99

if 'monday'

Normal processing

if 'tuesday'

Normal processing

if 'wednesday'

Normal processing

if 'thursday'

Normal processing

if 'Friday'

Normal processing

.........................


empid date val day name
-----------------------------------
1111 1/2/2008 1 Tuesday
1111 2/2/2008 1 Wednesday
1111 3/2/2008 1 Thursday
1111 4/2/2008 1 Friday
1111 5/2/2008 99 Saturday
1111 6/2/2008 55 Sunday
1111 7/2/2008 1
1111 8/2/2008 1
1111 9/2/2008 1
1111 10/2/2008 1
1111 11/2/2008 1

2222 6/2/2008 55 Sunday
2222 7/2/2008 5 Monday
2222 8/2/2008 5 Tuesday
2222 9/2/2008 5 Wednesday
2222 10/2/2008 5 Thursday
2222 11/2/2008 5 Friday
2222 12/2/2008 99 Saturday
2222 13/2/2008 5
2222 14/2/2008 5
2222 15/2/2008 5
2222 16/2/2008 5
----------------
TNX

georgev
Posting Yak Master

122 Posts

Posted - 2008-01-05 : 21:00:39
I don't like the look of what you're doing her but hey...

[CODE]
UPDATE #temp
SET val = CASE DatePart(dy, someDate)
WHEN 6 THEN 99
WHEN 7 THEN 55
WHERE DatePart(dy, someDate) IN (6, 7)
[/CODE]


George
<3Engaged!
Go to Top of Page
   

- Advertisement -