insert lines / append text [begin end between before after mysecondtext blankline file]
insert text on the line[mytext before after column blankline]
sort & rearrange order [sort second column delimiter split]
convert /split / change structure of lines
loop , repeat muppix commands [mycommand mysecondcommand]
save / append files [directory extension database insert]
www.muppix.co linux basic navigation commands in the terminal window
tools to help view the output
SQL table commands
Muppix provides innovative solutions and Training to make sense of large scale data.
SELECT '' UNION ALL SELECT mycolumn FROM mytable | insert blankline above beginning of all the lines |
SELECT 'mytext' UNION ALL SELECT mycolumn FROM mytable | insert 'mytext' above all the lines/above beginning of lines |
SELECT (CASE WHEN mycolumn LIKE '%mytext%' THEN 'mysecondtext' ELSE '' END)+ mycolumn as mynewcol ,* FROM mytable | if 'mytext' on line, insert word/column 'mysecondtext ' at beginning of line |
INSERT INTO mytable(mycolumn) VALUES ('mytext') | insert 'mytext' below end of all lines |
SELECT mycolumn FROM mytable UNION ALL SELECT '' | insert blankline below the end of all the lines |
SELECT mycolumn FROM mytable UNION ALL SELECT 'mytext' | insert below the end of the lines 'mytext' |
SELECT mycolumn FROM mytable UNION ALL SELECT 'mytext' UNION ALL SELECT 'mytext' | insert 2 blanklines and the line with 'mytext' at end of the lines, below the lines |
WITH mytmp AS (SELECT id = 1 UNION ALL SELECT id + 1 FROM mytmp WHERE id < 2 )SELECT id FROM mytmp | insert table 2 lines, loop ID 1 to 2 |
;WITH tmp AS (SELECT 1 AS ID UNION ALL SELECT ID + 1 AS ID FROM tmp WHERE tmp.ID < 2) SELECT * INTO mynewtable FROM tmp | insert new text/table of 2 lines, with numbers 1 to 2 |
SELECT * INTO T10 FROM (SELECT 1 AS ID)X WHERE 1 = 0;WITH mytmp(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM mytmp WHERE n<10) INSERT T10 SELECT * FROM mytmp | insert 10 lines, with loop ID 1 to 10 |
WITH X(id) AS (SELECT 1 FROM (SELECT 1 AS mycol) Y UNION ALL SELECT id+1 FROM X WHERE id+1 <= 11)SELECT * INTO T11 FROM X | insert 11 lines, loop |
WITH temp AS (SELECT ID=1 UNION ALL SELECT ID+1 FROM temp WHERE ID < 100) SELECT ID INTO T100 FROM temp | insert 100 lines, loop ID 1 to 100 |
SELECT ('mytext') AS mynewcol,* FROM mytable | insert 'mytext ' / column before beginning of the line ie: sed 's/^/ /' #indent lines |
SELECT IIF(0< CHARINDEX(' ',mycolumn,1), SUBSTRING( mycolumn,0 ,CHARINDEX( ' ',mycolumn+' '))+ 'mytext' + SUBSTRING( mycolumn,CHARINDEX( ' ',mycolumn+' '),999) + mycolumn ,mycolumn),* from mytable | insert 'mytext' after begin column |
SELECT *,('mytext') AS mynewcol FROM mytable | insert 'mytext' or column after the end of the line |
ALTER TABLE mytable ADD mynewcol VARCHAR(12) NULL DEFAULT(NULL); | insert 'mytext' or column after the end of the line |
change width of character field | |
ALTER TABLE mytable ADD mynewcol1 VARCHAR(25) NULL DEFAULT(NULL), mynewcol2 NUMERIC NULL DEFAULT(NULL), mynewcol3 BIGINT DEFAULT(NULL); | insert column & second & third column |
SELECT REPLACE(mycolumn, 'mytext','mysecondtextmytext') FROM mytable | insert 'mysecondtext' before 'mytext' |
SELECT REPLACE(mycolumn, 'mytext','mytextmysecondtext') FROM mytable | insert 'mysecondtext' after 'mytext' |
SELECT mysecondcolumn + 'mytext' FROM mytable | insert 'mytext' after second column. TIP: to insert a new column use ' mytext' |
SELECT 'mytext' + mysecondcolumn FROM mytable | insert 'mytext' before second column TIP: to insert a new column use 'mytext ' |
SELECT IIF(0 | insert mysecondtext/column at beginning of line if line has 'mytext' |
SELECT IIF(0 | insert mysecondtext/column at end of line if line has 'mytext' |
SELECT REPLACE(mysecondcolumn,'mytext','mysecondtextmytext') FROM mytable | if 'mytext' is in second column, insert 'mysecondtext' before the second column |
SELECT REPLACE(mysecondcolumn,'mytext','mytextmysecondtext') FROM mytable | if 'mytext' is in second column, insert 'mysecondtext' after the second column |
SELECT REPLACE(mycolumn,'mytext', 'mysecondtextmytext') FROM mytable | if 'mytext' at the beginning of a line, insert 'mysecondtext' before 'mytext' |
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS myrow,* FROM mytable | insert linenumbers at the beginning of each line ie: find out linenumbers with 'mytext' : cat .txt| nl -ba |fgrep 'mytext' |
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY mycolumn) AS myrow, * FROM mytable ) X WHERE mycolumn ='mytext' | select lines with 'mytext' include linenumbers (usefull for large files & can delete section of lines , from fixed linenumbers ) |
SELECT *,ROW_NUMBER() OVER (ORDER BY mycolumn) AS mylinenumber FROM mytable | insert linenumbers (formated to 9 numbers) at end |
SELECT * FROM mytable ORDER BY mycolumn ASC | sort, but ignore case , uppercase or lowercase |
SELECT * FROM mytable ORDER BY mycolumn | sort by numbers ie: look at beginning column as numeric values and sort TIP: if there are punctuation characters, sort may not work & delete them |
SELECT * FROM mytable ORDER BY mysecondcolumn | sort on the second column TIP:beware of multiple spaces between columns |
SELECT * FROM mytable ORDER BY mysecondcolumn ORDER DESC | sort on second column but in reverse order |
SELECT mycolumn,mysecondcolumn FROM mytable GROUP BY mycolumn,mysecondcolumn ORDER BY mycolumn -- (only showing 2 columns here) | sort lines and then delete duplicate lines |
SELECT * FROM mytable ORDER BY LEN(CAST(mycolumn AS VARCHAR)) ASC | sort the lines of a file by length, shortest on top |
SELECT LEFT(mycolumn,2),* FROM mytable | select the beginning and second characters (fixed) of each line. delete after 2nd character. TIP: it s usually better to search for the text, rather than select a fixed nmber of characters : most often the data is not fully consistent |
SELECT SUBSTRING (mycolumn, 2,1+(8-2)) , * FROM mytable | select absolute/fixed character positions between second to 8th |
SELECT SUBSTRING(mycolumn,2,3)+ SUBSTRING(mycolumn,8,7) FROM mytable | select fixed characters 2 - 5, 8 - 15 |
SELECT SUBSTRING(mycolumn,2 ,9999) FROM mytable | select fixed text after the second character onwards, delete beginning 2 characters |
SELECT IIF(LEN(mycolumn)>0, SUBSTRING(mycolumn, 1, LEN(mycolumn)-1), '') FROM mytable | select 2 (fixed) characters from the end of line, delete before the second from end character |
SELECT t1.mycolumn, SPLIT.t1.value('.', 'VARCHAR(100)') AS mynew FROM (SELECT mycolumn ,CAST(' | replace spaces with newlines, convert/split text to a single list of words/products TIP:may need to replace punctuation with spaces first |
SELECT t1.mycolumn,mycol = REPLACE ((SELECT t2.mysecondcolumn AS 'data()' FROM mytable AS t2 WHERE t1.mycolumn = t2.mycolumn FOR XML PATH('')), ' ', ', ') FROM mytable AS t1 GROUP BY mycolumn | replace /delete newlines with spaces, convert list into a long single line TIP: if windows, us \r (carriage return (13)) instead of \n (10) |
SELECT mycolumn,STUFF((SELECT ',' + [mysecondcolumn] FROM mytable WHERE (mycolumn = t1.mycolumn) FOR XML PATH(''),TYPE).value('(./text())[1]','VARCHAR(MAX)'),1,2,'') AS mycol FROM mytable t1 | replace /delete newlines with spaces, convert list into a long single line,( group by second column) |
SELECT x.XmlCol.value('.','varchar(36)') AS mylist FROM (SELECT CAST(' | replace commas (mydelimiter = ',') with a newline ie: split all text with commas into a table of words/columns (structure) |
;WITH mytmp( mynewlist, mycolumn) AS (SELECT LEFT(mycolumn, CHARINDEX(',' ,mycolumn+',')-1) ,STUFF(mycolumn, 1, CHARINDEX(',' ,mycolumn+','), '') FROM mytable UNION all SELECT LEFT(mycolumn, CHARINDEX(',' ,mycolumn+',')-1) ,STUFF(mycolumn, 1, CHARINDEX(',' ,mycolumn+','), '') FROM mytmp WHERE mycolumn > '' ) SELECT mynewlist FROM mytmp -- mycolumn must be VARCHAR(MAX) | replace commas (mydelimiter = ',') with a newline ie: split all text with commas into a table of single words/columns (structure) |
SELECT t1.*, t2.mytmp AS mysplit FROM (SELECT *, CAST(' | replace semicolon (mydelimiter = ';') with a newline ie: split/convert text with semicolon into a table of words/columns (structure) |
CREATE FUNCTION [dbo].[CSVToTable] (@InStr VARCHAR(MAX))RETURNS @TempTab TABLE (id VARCHAR(1000) not null) AS BEGIN; SET @InStr = REPLACE(@InStr + ',', ',,', ',') DECLARE @SP INT DECLARE @VALUE VARCHAR(1000) WHILE PATINDEX('%,%', @INSTR ) <> 0 BEGIN SELECT @SP = PATINDEX('%,%',@INSTR) SELECT @VALUE = LEFT(@INSTR , @SP - 1) SELECT @INSTR = STUFF(@INSTR, 1, @SP, '') INSERT INTO @TempTab(id) VALUES (@VALUE) END RETURN END GO DECLARE @LIST VARCHAR(200);SET @LIST = '1234567,mytext,12345';SELECT * FROM mytable WHERE mycolumn IN (SELECT * FROM dbo.CSVToTable( @LIST )) | replace commas (mydelimiter = ',') with a newline ie: split all text with commas into a table of words/columns (structure) |
SELECT mycolumn, UPPER( mysecondcolumn) ,mythirdcolumn FROM mytable | convert second column to uppercase , '|' as mydelimiter |
SELECT mycolumn, COUNT(*) AS times FROM mytable GROUP BY mycolumn | select how many occurrence , ie: pivot table |
SELECT mycolumn, SUM(mysecondcolumn) AS mytotal FROM mytable GROUP BY mycolumn | sum/add up second column for each unique occurrence of the beginning column (like SQL GROUP BY) |
SELECT mycolumn, COUNT(*) OVER (PARTITION BY mycolumn,mysecondcolumn) AS myCOUNTIF, COUNT(mysecondcolumn) OVER (PARTITION BY mycolumn,mysecondcolumn) AS mynewcol2, COUNT(*) OVER () AS mytotal FROM mytable | count how many different types (group by) of mycolumn and mysecondcolumn, how many total mycolumn |
SELECT mycolumn,mysecondcolumn COUNT(mycolumn) FROM mytable GROUP BY mycolumn,mysecondcolumn | count how many different types (group by) of mycolumn and mysecondcolumn, how many total mycolumn |
SELECT mycolumn, MAX( mysecondcolumn) AS mytotal FROM mytable GROUP BY mycolumn | maximum value of second column for each unique occurrence of the beginning column (like SQL GROUP BY) |
SELECT mycolumn, MAX( mysecondcolumn) AS mytotal FROM mytable GROUP BY mycolumn | maximum value of second column for each unique occurrence of the beginning column, include all columns (like SQL GROUP BY) |
SELECT mycolumn, MIN( mysecondcolumn) AS mytotal FROM mytable GROUP BY mycolumn | minimum value of second column for each unique occurrence of the beginning column (like SQL GROUP BY) |
SELECT SUM(mysecondcolumn) OVER (ORDER BY mycolumn,mythirdcolumn) AS mytotal ,* FROM mytable | sum up second column - running total |
SELECT mycolumn ,COUNT(*) FROM mytable GROUP BY mycolumn | occurrence based on begin column, include number of entriies |
SELECT mycolumn,mysecondcolumn,COUNT(*) FROM mytable GROUP BY mycolumn,mysecondcolumn | occurrence based on begin column & secondcolumn, include number of entries |
SELECT * FROM (SELECT *,LAG (mycolumn,1) OVER (PARTITION BY mycolumn ORDER BY mycolumn DESC) AS mytmp FROM mytable) X WHERE mytmp IS NULL | based on begin column find begin line of each unique group |
SELECT *,ROW_NUMBER() OVER (ORDER BY mycolumn DESC ) AS ID INTO #myloop FROM (SELECT DISTINCT mycolumn FROM mytable) X | create looping dates temp table (1) |
DECLARE @Period INT;DECLARE @i INT = 1 ;DECLARE @End INT = 10; WHILE @i <= @End BEGIN;SET @Period = (SELECT mycolumn FROM #myloop WHERE ID=@i) ;SELECT @Period;SET @i = @i + 1;END; | loop through each dates (2) |
DECLARE @i INT = 1 ;DECLARE @End INT = 10; WHILE @i <= @End BEGIN; SELECT * FROM(SELECT ROW_NUMBER() OVER (ORDER BY mycolumn) AS myrow,* FROM mytable) X WHERE myrow = @i; SET @i = @i + 1;END; | loop some command 10 times |
SELECT *, ISNULL(parent,'') + '-' + child AS combikey INTO mytables FROM (SELECT ROW_NUMBER() OVER (ORDER BY parent) AS linenumber,* FROM (SELECT NULL AS parent ,* FROM (SELECT DISTINCT t1.parent AS child FROM mytable t1 LEFT OUTER JOIN mytable t2 ON t2.child = t1.parent WHERE t2.child IS NULL) X UNION SELECT parent,child FROM mytable) Y)Z | parent child tree 1 - mytable = parent,child. insert parents lines as NULLS and linenumber |
SELECT t1.linenumber,t1.parent,t1.child,t1.combikey INTO #mytabless FROM #mytables t1 LEFT JOIN #mytables t2 ON (t1.child+t1.parent)= (t2.parent + t2.child) WHERE t2.linenumber>t1.linenumber UNION SELECT t1.linenumber,t1.parent,t1.child,t1.combikey FROM #mytables t1 LEFT JOIN #mytables t2 ON (t1.child+t1.parent)= (t2.parent + t2.child) WHERE t2.parent IS NULL | parent child tree 2 - mytabless , strip duplicate parent = child & child = parent |
SELECT t6.linenumber AS ID,t7.linenumber AS IDparent,t6.child AS jobno INTO mytableult FROM #mytabless t6 JOIN (SELECT linenumber AS IDparent, child AS jobno ,* FROM (SELECT t1.linenumber,t3.parent,t3.child ,t3.combikey FROM #mytabless t1 CROSS APPLY (SELECT * FROM #mytabless t2 WHERE t1.child=t2.parent) t3 UNION SELECT 0 AS linenumber,t5.parent,t5.child,t5.combikey FROM #mytabless t5 WHERE parent IS NULL )x )t7 ON t6.combikey = t7.combikey | parent child tree 3 - line up ultimate parent/child table , ready for recursive sql |
WITH CTE AS ( SELECT id, idparent, jobno, CONVERT(VARCHAR(MAX),jobno) AS ListJob FROM #mytableult WHERE idParent = 0 UNION ALL SELECT t.id, t.idparent, t.jobno, c.ListJob + '/' + CONVERT(VARCHAR(MAX),t.jobno) AS ListJob FROM #mytableult t INNER JOIN CTE c ON t.idParent = c.id) SELECT * FROM CTE ORDER BY jobno; | parent child tree 4 final - each child with all its parents loop recursively |
SELECT mycolumn, ( mysecondcolumn+mythirdcolumn+myfourthcolumn)/3 FROM mytable | sum/ add-up second, third & fourth column - divide - average |
SELECT IIF(mycolumn IS NULL,1, mycolumn)/ IIF(0=ISNULL(mysecondcolumn ,0),.001,mysecondcolumn ),* FROM mytable | divide 2 numbers in sql without errors |
DECLARE @sql varchar(1000);DECLARE @columns varchar(75);DECLARE @text varchar(75);SET @columns = 'mycolumn , mysecondcolumn, mythirdcolumn';SET @text = '''mytext''';SET @sql = 'SELECT ' + @columns + ' FROM mytable WHERE mycolumn = ' + @text;EXEC (@sql) | execute sql ,insert dynamic list of columns, mycolumn, mysecondcolumn |
SELECT * FROM mytable; OUTPUT TO 'c:\\muppix\\myfile.txt' FORMAT TEXT QUOTE '"' WITH COLUMN NAMES | save results to .txt in this directory (TIP: pls note there is no "|" with this command ) ie: ls -al >myfile.txt |
SELECT * INTO #mynewtable FROM mytable -- #mytemptable only last during this SQL session | save results to temporary mytable |
INSERT INTO mytable SELECT * FROM mysecondtable | insert lines of the result below end of .txt and save (even if it doesnt exist yet) ie: grep mytext * >>myfile.txt |
SELECT * INTO mysecondtable FROM mytable -- new SQL table | save as text file for viewing in notepad *.txt |
SELECT * INTO mysecondtable [IN myotherdatabase] FROM mytable -- new SQL table from another database | copy/save as text file |
SELECT * FROM mytable; OUTPUT TO 'c:\\muppix\\myspreadsheet.csv' FORMAT TEXT QUOTE '"' WITH COLUMN NAMES | save results to excell/spreadsheet or msaccess database in this directory. TIP: ensure the columns have a delimiter such as "|" |
SELECT * FROM mytable UNION ALL SELECT * FROM mysecondtable -- but make sure all colunmds are the same | insert .txt lines at end/below mysecondfile.txt and mysecondfile.txt (even if mysecondfile doesnt exist yet) |
SELECT t1.*,t2.* FROM mytable t1 JOIN mysecondtable t2 ON t1.mycolumn = t2.mycolumn | insert mysecondfile after(to right of) . side by side as 2 columns with '|' as mydelimiter between files |
SELECT t1.* , t2.* FROM mytable t1 INNER JOIN mysecondtable t2 ON t1.mycolumn = t2.mycolumn | insert after columns from mysecondfile, based on the begin column of each file. only select matching lines. excel VLOOKUP(A2,mysecondfile!A:B,2) TIP: ensure are linux files, ie: dos2unix myfile |
SELECT * FROM mytable t1 CROSS APPLY (SELECT * FROM mysecondtable t2 WHERE t1.mycolumn = t2.mycolumn )X | insert after columns from mysecondfile, based on the begin column of each file. only select matching lines. excel VLOOKUP(A2,mysecondfile!A:B,2) TIP: ensure are linux files, ie: dos2unix myfile |
SELECT mytable.mycolumn, mytable.mysecondcolumn, mysecondtable.mythirdcolumn,mysecondtable.myfourthcolumn FROM mytable LEFT JOIN mysecondtable ON mytable.mycolumn = mysecondtable.mycolumn | insert after columns from mysecondfile, based on the begin column of each file. include non-matching lines. excel VLOOKUP(A2,mysecondfile!A:B,2) TIP: ensure are linux files, ie: dos2unix myfile |
SELECT mytable.* , mysecondtable.* FROM mytable INNER JOIN mysecondtable ON mytable.mycolumn = mysecondtable.mycolumn | insert after columns from mysecondfile, based on the begin column of each file. include non-matching lines, mydelimiter = '|' TIP: ensure are linux files, ie: dos2unix myfile |
SELECT M.mycolumn,M.mysecondcolumn,D.mydatecolumn,D.mylastcolumn FROM mytable M CROSS APPLY( SELECT TOP 2 D.mycolumn,mydatecolumn,mylastcolumn FROM mysecondtable D WHERE M.mycolumn = D.mycolumn ORDER BY D.mydatecolumn DESC )D | select mycolumn and mysecondcolumn from mytable and lines of last (end) two dates for each mycolumn from mysecondtable |
SELECT * FROM mytable t1 CROSS APPLY (SELECT * FROM mysecondtable t2 WHERE t1.mycolumn = t2.mycolumn) X | joins 2 files by key in begin column of both files,like excel VLOOKUP .txt may need dos2unix & must be sorted & only use 1st column to index |
SELECT t1.*,t3.* FROM mytable t1 OUTER APPLY(SELECT TOP 1 * FROM mysecondtable t2 WHERE t1.mycolumn = t2.mycolumn ORDER BY mysecondcolumn) t3 | select whole of mytable & joins only single lines from secondtable / file where it can (but not add extra lines from second table ie outer join) exactly like VLOOKUP, show all columns |
select whole of mytable & joins only single lines from secondtable / file where it can (but not add extra lines from second table ie outer join) exactly like VLOOKUP, show all columns |
CREATE DATABASE mydatabase | create database |
USE mydatabase | goto the dataset where the data is, ie goto C: drive (mydrive) or USB on windows. TIP: for linux/Apple ,use mount to show all harddrive names |
EXPLAIN mytable | all filesnames (including socalled hidden files) and time stamps in mydir- this directory only filenames & details, this directory only |
DECLARE @SQL NVARCHAR(MAX) = ''; SELECT @SQL = @SQL + 'SELECT ''' + t1.name + ''' AS DatabaseName, t.name AS TableName, t2.name AS ColumnName, t.modify_date FROM ' + t1.name + '.sys.tables t INNER JOIN ' + t1.name + '.sys.columns t2 ON t2.object_id = t.object_id UNION ALL ' FROM sys.databases t1 WHERE t1.name IN('mydatabase'); SET @SQL = left(@SQL, LEN(@SQL) - 10); EXEC sp_executesql @SQL | select all filenames (& all its size/date information) in mydir & all sub directory, also select each subdirectory name with each file |
SELECT * FROM mytable | select all lines of .txt ie: cat muppix.txt |
SELECT TOP 10 * FROM mytable ORDER BY mycolumn ASC | begin 10 lines of file TIP: try all your commands on just these 20 lines ie: cat muppix.txt | head -20 |
SELECT TOP 10 * FROM mytable ORDER BY mycolumn DESC | end 10 lines of file TIP: use this subset of the file to try all your commands ie: cat muppix.txt | tail |
SELECT SUBSTRING(mycolumn,2,8-2) FROM mytable | delete character(s) before 2, select between character 2 (second) and 88. delete after 88th (fixed) |
SELECT LEFT( mycolumn,88) FROM mytable | only begin / less than 88 (fixed) characters ie: cat .txt | cut -c-88 |
SELECT COUNT(*) FROM mytable | how many lines in the list |
SELECT COUNT(*) FROM mytable | how many lines in the list / ie: how many mytext found in myfile: cat myfile.txt | fgrep mytext | wc -lc |
SELECT name, database_id, create_date FROM sys.databases | names of all hard-drives (mydrive) on this version of linux & size. TIP: goto using these harddrive names |
SELECT RTRIM( LTRIM( REPLACE( REPLACE( mycolumn,' ' ,' ' ),' ' ,' '))) FROM mytable | delete/replace multiple/duplicate/consecutive spaces with single space/blank, also deletes begin spaces. easy to view ie: cat .txt | awk -v OFS=" " '$1=$1' |
SELECT * FROM mytable ORDER BY CONVERT(binary(25),mycolumn) ASC | sort lines |
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY mycolumn ORDER BY mycolumn ) AS myrowno FROM mytable )X WHERE myrowno =1 | sort lines and then delete duplicate lines |
SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql ORDER BY execquery.last_execution_time DESC | history of 100 mycommands i recently used in this terminal |
SELECT TOP 2 * FROM mytable ORDER BY mycolumn ASC | select beginning (fixed) and second lines |
SELECT TOP 2 * FROM mytable ORDER BY mycolumn ASC | select beginning (fixed) and second lines |
SELECT LEFT( mycolumn,2) FROM mytable | only select beginning and second characters. ie: cut -c-77 to quickly view text, beginning 77 characters (not wrap long lines) |
SELECT T1.text FROM sys.dm_exec_cached_plans AS T2 CROSS APPLY sys.dm_exec_sql_text(T2.plan_handle) AS T1 WHERE T1.text LIKE N'%mytext%' | out of the 100 recent mycommands, select those with 'mytext' |
SELECT ROW_NUMBER() OVER (ORDER BY mycolumn) AS linenumber,* FROM mytable | insert linenumbers at beginning of line ie: find out linenumbers with 'mytext' : cat .txt| cat -n |fgrep 'mytext' |