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.
Author |
Topic |
hai
Yak Posting Veteran
84 Posts |
Posted - 2009-04-02 : 08:49:29
|
I have a file that contain a list of ranges...assign and ID to the another table base on the range assigned. eg:tblRange:ID, Ranges:1,1-1002,101-2003,201-400tblMainid,sum,rangeID1,100,12,50,13,400,3In the past I have used case statement, but code the range in:select id,sum,case when sum between 1 and 100 then 1 when sum between 101 and 200 then 2 when sum between 201 and 400 then 3from table. |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-04-02 : 09:15:11
|
I'm sorry...but what is the question...Can you explain what you want to get done? |
|
|
maeenul
Starting Member
20 Posts |
Posted - 2009-04-02 : 09:27:19
|
I am not sure what exactly your question is. But you can take care of the case statement. You have to give end at the end of case statement.select id,sum,case when sum between 1 and 100 then 1when sum between 101 and 200 then 2when sum between 201 and 400 then 3endfrom table.-----------------------maeenulhttp://sqlservertipsntricks.blogspot.com |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-02 : 09:40:29
|
[code]create table #tblRange (ID int , Ranges varchar(100))insert into #tblRange select 1,'1-100'union allselect 2,'101-200' union allselect 3,'201-400' create table #tblMain (ID int , sum float)insert into tblMain select 1,100 union allselect 2,50 union allselect 3,400 select a.id,a.sum,b.ID from #tblMain a join #tblRange b on sum between left(Ranges,charindex('-',Ranges)-1)and reverse(left(reverse(Ranges),charindex('-',reverse(Ranges))-1))[/code] |
|
|
hai
Yak Posting Veteran
84 Posts |
Posted - 2009-04-02 : 13:44:11
|
thank you very much Sakets_2000 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-02 : 13:46:11
|
np |
|
|
|
|
|
|
|