* * * * * * S Q L S E R V E R G O T C H A * * * * * * *!* If using ADO, there is a problem using a *!* parameterized query on an NCHAR data type. A SelectCmd like *!* *!* cCustomerID = [M%] *!* select * from Customers where CustomerID like ?cCustomerID *!* *!* will return no records because in the Northwind database where *!* this example was tested against, the CustomerID is a NCHAR(5) *!* data type. When the SQL is passed to the server, the parameter *!* value of 'M%' gets RPADded with spaces to make the paramter *!* value a width to match the field width in the table. In other *!* words the values is passed as 'M% '. This does not happen *!* with NVARCHAR datatypes. The workaround is to create your SQL as: *!* *!* cCustomerID = [M%] *!* select * from Customers where CustomerID like RTRIM(?cCustomerID)If interested, you can get my builder and all the source code including the comments above plus additional comments on the CA from:
SELECT * FROM Customer WHERE FirstName LIKE ?vp_FirstName>
exec sp_executesql N'select * FROM Customer WHERE Customer.FirstName LIKE @P1 ', N'@P1 char(30)', '% ' >>