SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


help insert employee to #temp table all month


help insert employee to #temp table all month

Author
Message
midan1
midan1
SSC-Addicted
SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)

Group: General Forum Members
Points: 440 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



Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89135 Visits: 41143
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
David McFarland
David McFarland
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1233 Visits: 214
Whahuh?
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89135 Visits: 41143
It's a "hint" on how to post data... Tongue

--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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
David McFarland
David McFarland
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1233 Visits: 214
My "Whahuh?" was directed at the OP, not your link. Smile

I can't tell what they want to accomplish no matter how many times I read it.
Kenneth.Fisher
Kenneth.Fisher
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4350 Visits: 2033
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search