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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Modifying data

Author  Topic 

LOLCatLady
Starting Member

24 Posts

Posted - 2010-07-27 : 12:03:35
This is probably a pretty basic question, but it's been a year and a half since I've worked with SQL so my brain has lost a lot.

I am running a query to pull data within a range of codes: 3157 - 3174. I need to add a column that shows each of the codes in the range as a single code, preferably the first one 3157.

How can I do this? (I used to know how, but I'm drawing a complete blank!)

Sachin.Nand

2937 Posts

Posted - 2010-07-27 : 12:06:30
select * from table where code between 3157 and 3174


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

LOLCatLady
Starting Member

24 Posts

Posted - 2010-07-27 : 12:19:58
quote:
Originally posted by Idera

select * from table where code between 3157 and 3174


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH



I have that. What I need to do is for each of the codes 3157 - 3174 I want another column where I can change them to all the same code.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-27 : 12:25:13
What do you mean by "same code"?Can you post some expected o/p.


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-07-27 : 12:32:26
Liek this?
select *, '3157 - 3174' AS CodeRange  from table where code between 3157 and 3174
If not, please do as Idera suggested and post some DDL, DML and expected output. Here is a link that might help with that:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

LOLCatLady
Starting Member

24 Posts

Posted - 2010-07-27 : 12:53:42
quote:
Originally posted by Idera

What do you mean by "same code"?Can you post some expected o/p.


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH



For all the codes within the range 3157 - 3174, I want to rename them all to 3157:
3157 to 3157
3158 to 3157
3159 to 3157
etc.

My query will create a new table to do additional analysis, and it would make it easier to combine the ranges of codes.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-27 : 12:56:14
quote:
Originally posted by LOLCatLady

quote:
Originally posted by Idera

What do you mean by "same code"?Can you post some expected o/p.


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH



For all the codes within the range 3157 - 3174, I want to rename them all to 3157:
3157 to 3157
3158 to 3157
3159 to 3157
etc.

My query will create a new table to do additional analysis, and it would make it easier to combine the ranges of codes.



select '3157' as code from table where code between 3157 and 3174


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

LOLCatLady
Starting Member

24 Posts

Posted - 2010-07-27 : 14:49:54
Perfect! That worked exactly how I needed it to. Thank you for your help!
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-28 : 01:19:07
quote:
Originally posted by LOLCatLady

Perfect! That worked exactly how I needed it to. Thank you for your help!



Welcome


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page
   

- Advertisement -