SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case Statements
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rds207
Posting Yak Master

198 Posts

Posted - 02/04/2010 :  19:14:57  Show Profile  Reply with Quote
Hi

Could any body please help me writing the case statements for the below insert query from the below code table ..

Code Table:

RUNTIME_CODE RUNTIME_CATEGORY CATEGORY_RANK
1 0 - 5 min 1
2 5 - 15 min 2
3 15 - 30 min 3
4 30 - 1 hr 4
5 1 - 2 hrs 5
6 2 - 5 hrs 6
7 5 - 10 hrs 7
8 10 hrs - 20 hrs 8
9 20 hrs - 40 hrs 9
10 40+ hrs 10


My insert Query is below:

Insert INTO DW_T_ASW_JOBDATA(
[RUNTIME_CODE],
[RUNTIME_MIN]
)(
SELECT
NULL,
DATEDIFF(MINUTE,E.EC_START_TIME,E.EC_FINISH_TIME),
E.EC_START_TIME,
dateadd(HOUR,8,EC_START_TIME)
FROM dbo.DW_T_EC_TGT E WHERE EC_STEP_INDEX IS NULL)

Expected Output:
RUNTIME_CODE RUNTIME_CATEGORY RUNTIME_MIN START_TIME
8 10 hrs - 20 hrs 811 2009-11-05 06:34:09.000
8 10 hrs - 20 hrs 704 2009-11-05 09:48:05.000
8 10 hrs - 20 hrs 772 2009-11-05 09:51:27.000
4 30 - 1 hr 57 2009-11-04 02:10:22.000
7 5 - 10 hrs 340 2009-11-02 10:10:58.000
7 5 - 10 hrs 439 2009-11-04 04:37:06.000

-Thanks in Advance

EugeneLim11
Posting Yak Master

167 Posts

Posted - 02/05/2010 :  02:46:31  Show Profile  Visit EugeneLim11's Homepage  Reply with Quote
Your Insert statement is very funny. There are two columns to insert into, but I counted 4 columns in your select statement. How do you put 4 columns into 2 columns?

What exactly are you trying to accomplish?
Go to Top of Page

Sachin.Nand
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 02/05/2010 :  03:02:59  Show Profile  Reply with Quote
Why do you need the case statement?

PBUH
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 02/05/2010 :  08:51:02  Show Profile  Reply with Quote
I'm sure OP is not giving us full picture. There are values in output coming from columns which he has not included in sample data. Can I ask you to give full sample data in below format

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

rds207
Posting Yak Master

198 Posts

Posted - 02/05/2010 :  14:14:31  Show Profile  Reply with Quote
I know i had some wrong statement here but i figured out the solution for this question , Thank you,

how do i close the topic ?
Go to Top of Page

Kristen
Test

United Kingdom
22415 Posts

Posted - 02/06/2010 :  01:56:57  Show Profile  Reply with Quote
No need to close the topic, but some people (very few actually!!) re-edit their first post and change the Subject to append "[RESOLVED]"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000