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 2000 Forums
 Transact-SQL (2000)
 [SOLVED ]Calculate Values

Author  Topic 

Pace
Constraint Violating Yak Guru

264 Posts

Posted - 2006-12-11 : 10:43:47
Hi All,

Im racking my brain with this one...

I have this table
Id Code
-- --------
1 10101001
2 10101002
3 10102001
4 10102002
5 60101001
6 60101002
7 60102001
8 60102002
9 60201001
10 60201002
11 70101001
12 70101002

I need to query this table by the following
(select id, code from table1)
where the first number of Code > 1 and First number of code < 7 but including all after the first number.

I thought WHERE Code > '1%' and < etc... however its not right




"Impossible is Nothing"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-11 : 10:46:34
What is the datatype of Code column?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pace
Constraint Violating Yak Guru

264 Posts

Posted - 2006-12-11 : 10:47:11
integer

"Impossible is Nothing"
Go to Top of Page

Pace
Constraint Violating Yak Guru

264 Posts

Posted - 2006-12-11 : 10:51:38
Got it,

Select * from table where code between '1' and '7' + char(255)

"Impossible is Nothing"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-11 : 10:51:44
[code]select * from
(
select 1 num, 10101001 Code union all
select 2, 10101002 union all
select 3, 10102001 union all
select 4, 10102002 union all
select 5, 60101001 union all
select 6, 60101002 union all
select 7, 60102001 union all
select 8, 60102002 union all
select 9, 60201001 union all
select 10, 60201002 union all
select 11, 70101001 union all
select 12, 70101002) t
where (code/10000000) between 2 and 6[/code]


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-11 : 10:57:29
quote:
first number of Code > 1 and First number of code < 7


Do you want to include 1 and 7 as well?



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pace
Constraint Violating Yak Guru

264 Posts

Posted - 2006-12-11 : 11:04:26
ah sorry harsh I should have been a bit more fluid with the question.

I used 1 and 7 as testing vals... I wrote a SP so the initial numbers can be placed in by a user instead of having to hardcode it.

Thank you very much for your time.

Pace =)

"Impossible is Nothing"
Go to Top of Page
   

- Advertisement -