简体   繁体   中英

SQL Query Between Two Strings

I need Records between two strings passing through Parameters. @startString and @end String.
Between Query is possible between in these two strings?

10-00-000-000000 and 12-02-023-000000

Replace your column with Column1

SELECT * FROM TABLE1 WHERE CONVERT(BIGINT,REPLACE(@Column1,'-','')) BETWEEN 
CONVERT(BIGINT,REPLACE(@startString,'-','')) AND 
CONVERT(BIGINT,REPLACE(@endString,'-',''))

If your strings 10-00-000-000000 and 12-02-023-000000 are always in the same format xx-xx-xxx-xxxxxx (2-2-3-6 numbers) you can compare them on alphanumeric base just using

WHERE YourColumn BETWEEN @startString AND @endString

I'm assuming, that YourColumn is a string column with exactly the same format.

But if the numbering/format might differ you first have to specify What is the implicit sort order? Is 10-90-... higher or lower than 10-100-... ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM