String Comparison in T-SQL

Is it "legal" to compare strings in T-SQL such as what I am doing here?  I am having some issues with our accounting system not reflecting my "mappings" below and I was wondering if there was an issue with my code.  Another pair of eyes would be greatly apprecieated.

------------------------------------------------------------------------------------------------
update dbo.loadfile
set dbo.loadfile.cc = 206002, dbo.loadfile.product = 21, dbo.loadfile.acct = 59002
where dbo.loadfile.cc = 'VNG0'
      and ((dbo.loadfile.product >= '2300' and dbo.loadfile.product <= '5550')
            or (dbo.loadfile.product >= 'A021' and dbo.loadfile.product <= 'A388')
            or (dbo.loadfile.product >= 'D290' and dbo.loadfile.product <= 'FSTD')
            or dbo.loadfile.product in ('HNDG','K849','RMCO','RMPK','RMCT','RMPP','RMPE','RMLA','RMMM'))
      and dbo.loadfile.acct = 54110;

update dbo.loadfile
set dbo.loadfile.cc = 206002, dbo.loadfile.product = 80000277, dbo.loadfile.acct = 59002
where dbo.loadfile.cc = 'VNG0'
      and ((dbo.loadfile.product >= 'LITR' and dbo.loadfile.product <= 'LLTM')
            or dbo.loadfile.product in ('RMKT','RMLC','TCSV','ZSID'))
      and dbo.loadfile.acct = 54110;
-----------------------------------------------------------------------------------------------------
ltrain2015Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

muzzy2003Commented:
Yes it is legal. The only thing to bear in mind, is that where you do:

dbo.loadfile.product = 80000277

if product is a text field, SQL Server's default approach is to attempt to cast all the values in the product column to integer values in order to do the comparison. If it does not contain exclusively numerical values, you will get an error. In this case, you should use:

dbo.loadfile.product = '80000277'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ShogunWadeCommented:
concur with muzzy
0
LowfatspreadCommented:
i think it really depends on what your case sensitivity is  for the database....


also do you really wish to allow '2300       zzz'  as a value?

since its an accounting system you may be better off categorising those values on a separate table
to allow for more auditablity...



0
muzzy2003Commented:
And collation, since the comparison contains inequalities with strings. Of course, you can cast (right word?) the value into the right collation before making the comparison to achieve the results you want anyway.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.