Friday, 18 December 2020

Export data from stored procedure to CSV

 -- xp_cmdshell must be enabled under server security

DECLARE @cmd as varchar(4000) = 'BCP "Exec BikeStores.dbo.Test" QUERYOUT "D:\1.csv" -c -t\^, -T -S' + @@servername

EXEC master..xp_cmdshell @cmd



SQL: Generate a range of numbers

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n FROM       (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),      (VALU...