Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using IN() and parameter
Message
From
08/02/2013 16:05:03
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01565428
Message ID:
01565562
Views:
44
>>>>SELECT [awb_pk]
>>>> ,[awb_keycode]
>>>> ,[awb_manifestdate]
>>>> ,[awb_manifestnumber]
>>>> ,[awb_pieces]
>>>> ,[awb_weight]
>>>> ,[awb_cusfk]
>>>> ,[awb_value]
>>>> ,[awb_freight]
>>>> ,[awb_fuel]
>>>> ,[awb_insurance]
>>>> ,[awb_number]
>>>> ,[awb_shipper]
>>>> ,[awb_description]
>>>> ,[cus_number]
>>>> FROM [dbo].[AirWayBills]
>>>> inner join [dbo].[Customers] on awb_cusfk = cus_PK
>>>> WHERE
>>>> (CHARINDEX(CONVERT(VARCHAR(10), [awb_manifestnumber]), @awb_manifestnumber) > 0)
>>>
>>>This is bad and incorrect advice. Don't use such code.
>>
>>Could you explain why?
>
>By two reasons - you will not be able to use an index on awb_manifestNumber if it exists and also your code may produce wrong results, say, your have number 11 in the list, but 1 will be found as a match.

OK, I was asuming, all the numbers would be of the same length.

>
>Also, see this great Erland's Sommarskog article where he explains it:
>http://www.sommarskog.se/arrays-in-sql.html
>
>You can start from the second link (for 2005) although I think he explains it in all the links also.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform