Groups | Blog | Home
all groups > sql server (alternate) > october 2004 >

sql server (alternate) : Compare two column values with leading zeros


kattukuyil NO[at]SPAM hotmail.com
10/6/2004 6:57:42 AM
Hey,

This is what I would like to do:
===========
Declare @chvBOLNumber
Set @chvBOLNumber='0001234'
Select * from BOL where BOLNumber=@chvBOLNumber
I want to return the row/rows when BOLNumber=1234
============

The problem is the leading zeros. @chvBOLNumber can be 01234 or 001234 or ...

Hope the above makes sense. How can I do this ? (probably using wildcards)

Robin Tucker
10/6/2004 3:10:01 PM
Perhaps try an integer comparison instead by converting the number to
integer:

SELECT * from BOL where CONVERT(INTEGER, BOLNumber) = 1234

(no idea if this syntax is correct!)

[quoted text, click to view]

Simon Hayes
10/6/2004 4:16:37 PM

[quoted text, click to view]

For questions like this, it's important to know the data types involved, but
assuming that BOLNumber is an integer, then you can try this:

Select *
from BOL
where BOLNumber = cast(@chvBOLNumber as int)

If this doesn't work as expected, please post the data types of BOLNumber
and @chvBOLNumber. In general, you should always try to post CREATE TABLE
and INSERT statements to provide some sample data - that way there's no
confusion over exactly what you need.

Simon

AddThis Social Bookmark Button