Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

help insert employee to #temp table all month Expand / Collapse
Author
Message
Posted Saturday, January 5, 2008 6:24 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, July 28, 2008 8:42 AM
Points: 302, Visits: 271
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


.........................
required output result

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



Post #439283
Posted Saturday, January 5, 2008 8:27 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: 2 days ago @ 1:53 PM
Points: 35,366, Visits: 31,905
http://www.sqlservercentral.com/articles/Best+Practices/61537/

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #439299
Posted Saturday, January 5, 2008 11:12 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, December 8, 2008 8:42 AM
Points: 775, Visits: 214
Whahuh?
Post #439315
Posted Sunday, January 6, 2008 12:01 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: 2 days ago @ 1:53 PM
Points: 35,366, Visits: 31,905
It's a "hint" on how to post data... :P

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #439321
Posted Sunday, January 6, 2008 3:26 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, December 8, 2008 8:42 AM
Points: 775, Visits: 214
My "Whahuh?" was directed at the OP, not your link. :)

I can't tell what they want to accomplish no matter how many times I read it.
Post #439332
Posted Sunday, January 6, 2008 9:21 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Monday, October 20, 2014 2:22 PM
Points: 3,466, Visits: 1,819
Ok I'm going to make a wild guess and say they are looking for a CASE statement to determine the weekday.

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

So
CASE WHEN [day name] = 'Saturday' THEN 99 WHEN [day name] = Sunday THEN 55 ELSE 1 END

At least I think that is part of it.

Although if I were you I would re-post using Jeff's Best Pratcties for posting doc. It would make things alot easier to understand.


Kenneth Fisher
I strive to live in a world where a chicken can cross the road without being questioned about its motives.
--------------------------------------------------------------------------------
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Link to my Blog Post --> www.SQLStudies.com
Post #439342
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse