Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using IN() and parameter
Message
 
 
À
08/02/2013 14:17:10
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01565428
Message ID:
01565527
Vues:
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.

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.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform