Monthly Archives: February 2015

T-SQL :- How to Search String in all Stored Procedures across All User Defined Databases

There are many different ways to accomplish this tasks. Download Link https://gallery.technet.microsoft.com/T-SQL-How-to-Search-String-a1704fc6 The below examples uses undocumented sp’s to loop through all the user defined database to search the SP’s using given string CREATE TABLE #ProcSearch (databaseName VARCHAR(100),ROUTINE_CATALOG varchar(50),ProcName VARCHAR(128),RoutineType varchar(100),CreateDate … Continue reading

Posted in SQL, T-SQL | Tagged , , , , , | Leave a comment

T-SQL – Read CSV files using OpenRowSet

We can directly access a CSV file using T-SQL. Input file Configure server to run Ad Hoc Distributed Queries sp_configure ‘Ad Hoc Distributed Queries’,1 GO reconfigure GO Check for Microsoft Access Driver on your system SQL select [hour], UserID, [ReportLaunch] … Continue reading

Posted in SQL, Uncategorized | Tagged , , , , , , | 4 Comments

T-SQL – Query to get Distinct,Sorted, Comma Separated values in to a variable

CREATE TABLE #temp(name char(3)) INSERT INTO #temp VALUES (‘CD’) ,(‘AB’) ,(‘LM’) ,(‘BC’) ,(‘GH’) ,(‘KJ’) ,(‘AB’) DECLARE @cols AS NVARCHAR(MAX); SELECT @COLS = substring(list, 1, len(list) – 1) FROM (SELECT list = (SELECT DISTINCT name + ‘,’ FROM #temp ORDER BY … Continue reading

Posted in T-SQL | Tagged , , , | 10 Comments