SQL / T-SQL CASE SENSITIVE SELECT


A very simple method to force case sensitivity in a select statement:

SELECT * FROM DBusers WHERE username = ‘AGENT1’ AND password = ‘paSSworD’ COLLATE SQL_Latin1_General_Cp1_CS_AS


The above statement will only return rows where the password value is exactly paSSworD, case specific.


Advertisements

SQL – Output Data from SQL Server To File – BCP

The following BCP command selects data from a table called CUSTOMERS in the DATA database and exports it to a file called FOO_REPORT.CSV:


declare
@bcpcommand           varchar(1000)

 

SET @bcpcommand = ‘bcp “SELECT id, title, forename, surname, product FROM DATA.dbo.customers where product = ”FOO”” queryout C:\reports\FOO_REPORT.CSV -c -T”‘

EXEC master..xp_cmdshell @bcpcommand

 You can also output to .XLS and .TXT.