Tip 12 : Common T-SQL Escape Scenarios: Percent (%), Underscore (_)

Scenario 1 : You have a Purchase table with field named DiscountRate. The DiscountRate values can be true percentage such as "2.5%", "5.0%", or can be other values such as "N/A", "Fixed Rate", etc. You want all the records with true percentage.

To implement this, you need to escape percentage (%)

Scenario 2 : You have a Purchase table with fields of PurchaseType and Amount. The table uses vertical design. The PurchaseType values can be "xxxxx_gas", "xxxxx_food", etc. The "xxxxx" denotes value of a customer id. You want all the gasoline purchases, records ending with _gas.

To implement this, you need to escape underscore (_)

 

Published Thursday, February 11, 2010 6:34 PM by StanleyGu
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)