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
 General SQL Server Forums
 New to SQL Server Programming
 Case Statements

Author  Topic 

rds207
Posting Yak Master

198 Posts

Posted - 2010-02-04 : 19:14:57
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 - 2010-02-05 : 02:46:31
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

2937 Posts

Posted - 2010-02-05 : 03:02:59
Why do you need the case statement?

PBUH
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-05 : 08:51:02
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 - 2010-02-05 : 14:14:31
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

22859 Posts

Posted - 2010-02-06 : 01:56:57
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
   

- Advertisement -