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 2012 Forums
 Transact-SQL (2012)
 query with between

Author  Topic 

wided
Posting Yak Master

218 Posts

Posted - 2015-05-04 : 07:35:12
I need an application that can read data:

mytable

col1 col2
c001 401000
c002 402000
C003 411000
C004 412000
C005 421000
C006 422000
c007 423000

I have 2 input variables, such as 40 and 42 or 40 and 41 or 41 and 42

how to write the query, if I give 40 and 42


(between and starts, 2 at a time)

jleitao
Posting Yak Master

100 Posts

Posted - 2015-05-04 : 07:45:47
not sure if is that you really need. PLEASE, POST YOUR EXPECTED OUTPUT.

however try this:
SELECT * from mytable
where left(col2,2) between 40 and 42



------------------------
PS - Sorry my bad english
Go to Top of Page

wided
Posting Yak Master

218 Posts

Posted - 2015-05-04 : 07:58:14
the input variables can be for example 40 and 421
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-05-04 : 14:27:36
PLEASE, POST YOUR EXPECTED OUTPUT
Go to Top of Page
   

- Advertisement -