<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gary J Murphy</title>
	<atom:link href="http://garyjmurphy.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://garyjmurphy.com</link>
	<description></description>
	<lastBuildDate>Sat, 19 May 2012 06:46:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Search Through entire database for a value</title>
		<link>http://garyjmurphy.com/?p=115</link>
		<comments>http://garyjmurphy.com/?p=115#comments</comments>
		<pubDate>Fri, 07 Oct 2011 09:11:42 +0000</pubDate>
		<dc:creator>Garyjmurphy</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://garyjmurphy.com/?p=115</guid>
		<description><![CDATA[Query for searching the entire database for a string value To run this query in your own senerio, just change the &#8216;Cal&#8217; to any string you desire DECLARE @Database Varchar(255) DECLARE @Schema Varchar(255) DECLARE @TableName Varchar(255) DECLARE @ColumnName Varchar(255) DECLARE @SqlCmd Varchar(255) DECLARE @Search Varchar(1000) SET @Search = &#039;Gary&#039; SET @Search = &#039;&#039;&#039;%&#039;+@Search+&#039;%&#039;&#039;&#039; --PRINT @Search [...]]]></description>
				<content:encoded><![CDATA[<p>Query for searching the entire database for a string value</p>
<p>To run this query in your own senerio, just change the &#8216;Cal&#8217; to any string you desire</p>
<pre class="brush: sql; ">


DECLARE @Database Varchar(255)
DECLARE @Schema Varchar(255)
DECLARE @TableName Varchar(255)
DECLARE @ColumnName Varchar(255)
DECLARE @SqlCmd Varchar(255)
DECLARE @Search Varchar(1000)

SET @Search = &#039;Gary&#039;
SET @Search = &#039;&#039;&#039;%&#039;+@Search+&#039;%&#039;&#039;&#039;

--PRINT @Search

-- create temp table

CREATE TABLE #Results (TableName Varchar(255), ColumnName Varchar(255), Value Varchar(1000))

-- DROP TABLE #Results

DECLARE cur CURSOR READ_ONLY
FOR

SELECT A.TABLE_CATALOG, A.TABLE_SCHEMA, A.TABLE_NAME, B.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLES A
LEFT OUTER JOIN INFORMATION_SCHEMA.COLUMNS B ON A.TABLE_NAME = B.TABLE_NAME
WHERE A.TABLE_TYPE = &#039;BASE TABLE&#039;

OPEN cur

FETCH NEXT FROM cur
INTO @Database, @Schema, @TableName, @ColumnName

WHILE @@FETCH_STATUS = 0
BEGIN

--PRINT @Database, @Schema, @TableName, @ColumnName

PRINT &#039;@Database: &#039;+@Database
PRINT &#039;@Schema: &#039;+@Schema
PRINT &#039;@TableName: &#039;+@TableName
PRINT &#039;@ColumnName: &#039;+@ColumnName

SET @SqlCmd = &#039;INSERT INTO #Results (TableName, ColumnName, Value)&#039;
SET @SqlCmd = @SqlCmd + &#039; SELECT &#039;&#039;&#039;+@TableName+&#039;&#039;&#039;,&#039;&#039;&#039;+@ColumnName+&#039;&#039;&#039;,[&#039;+@ColumnName+&#039;] FROM &#039;+@Database+&#039;.&#039;+@Schema+&#039;.&#039;+@TableName+&#039; WHERE [&#039;+@ColumnName+&#039;] LIKE &#039;+@Search
PRINT @SqlCmd
exec (@SqlCmd)

FETCH NEXT FROM cur
INTO @Database, @Schema, @TableName, @ColumnName

END

CLOSE cur
DEALLOCATE cur

SELECT * FROM #Results

DROP TABLE #Results


</pre>
]]></content:encoded>
			<wfw:commentRss>http://garyjmurphy.com/?feed=rss2&#038;p=115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kill Active Processes for a particular SQL Database</title>
		<link>http://garyjmurphy.com/?p=97</link>
		<comments>http://garyjmurphy.com/?p=97#comments</comments>
		<pubDate>Sun, 10 Oct 2010 02:04:25 +0000</pubDate>
		<dc:creator>Garyjmurphy</dc:creator>
				<category><![CDATA[Procedures]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://garyjmurphy.com/?p=97</guid>
		<description><![CDATA[Below is a SQL script that I use all the time when it comes down to hung procedures and any unwanted processes that are left open. This below T-SQL could also be turned into a procedure quite easily and used as a cleanup job before running any backups. DECLARE @p_SPID int, @p_SQL nvarchar(2000), @dbName nvarchar(100) [...]]]></description>
				<content:encoded><![CDATA[<p>Below is a SQL script that I use all the time when it comes down to hung procedures and any unwanted processes that are left open. This below T-SQL could also be turned into a procedure quite easily and used as a cleanup job before running any backups.  </p>
<pre class="brush: sql; ">


DECLARE @p_SPID int, 
@p_SQL nvarchar(2000),
@dbName nvarchar(100)

-- Change the &#039;Database Name&#039; to the database that you intend to kill the processes for
SET @dbName = &#039;Database Name&#039;

DECLARE #cur_Processes CURSOR FOR 
SELECT p.SPID FROM master.dbo.sysprocesses AS p JOIN master.dbo.sysdatabases AS d ON( d.dbid = p.dbid ) 
WHERE d.Name = @dbName AND p.SPID &gt; 50 
-- AND spid &gt;= 51 (because spids of 50 or less are reserved for internal use.) 

OPEN #cur_Processes 

FETCH NEXT 
FROM #cur_Processes INTO @p_SPID 

WHILE @@FETCH_STATUS = 0 

BEGIN SET @p_SQL = &#039;KILL &#039; + CONVERT( nvarchar(30), @p_SPID ) 

PRINT @p_SQL EXECUTE( @p_SQL ) 

FETCH NEXT FROM #cur_Processes INTO @p_SPID END 

CLOSE #cur_Processes 
DEALLOCATE #cur_Processes 


</pre>
]]></content:encoded>
			<wfw:commentRss>http://garyjmurphy.com/?feed=rss2&#038;p=97</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sql Object Schema</title>
		<link>http://garyjmurphy.com/?p=93</link>
		<comments>http://garyjmurphy.com/?p=93#comments</comments>
		<pubDate>Wed, 30 Jun 2010 05:49:58 +0000</pubDate>
		<dc:creator>Garyjmurphy</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://garyjmurphy.com/?p=93</guid>
		<description><![CDATA[So inorder to Find a table schema in sql you have two options -- this will show all tables within this database SP_TABLES -- this is a more selective search select * from INFORMATION_SCHEMA.tables WHERE TABLE_NAME = this can also be done with columns -- this will show all column definations within the table specfied [...]]]></description>
				<content:encoded><![CDATA[<p>So inorder to Find a table schema in sql you have two options</p>
<pre class="brush: sql; ">


-- this will show all tables within this database
SP_TABLES

-- this is a more selective search
select * from
INFORMATION_SCHEMA.tables
WHERE TABLE_NAME =


</pre>
<p>this can also be done with columns</p>
<pre class="brush: sql; ">


-- this will show all column definations within the table specfied
SP_Columns

-- this is a more selective search on one or many views at one time
select * from
INFORMATION_SCHEMA.columns
WHERE TABLE_NAME =


</pre>
]]></content:encoded>
			<wfw:commentRss>http://garyjmurphy.com/?feed=rss2&#038;p=93</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>using OPENROWSET to import excel files into Sql tables</title>
		<link>http://garyjmurphy.com/?p=47</link>
		<comments>http://garyjmurphy.com/?p=47#comments</comments>
		<pubDate>Mon, 07 Jun 2010 13:18:35 +0000</pubDate>
		<dc:creator>Garyjmurphy</dc:creator>
				<category><![CDATA[Procedures]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://garyjmurphy.com/?p=47</guid>
		<description><![CDATA[As I am currently looking into ways in which I could automate dataloading from multiple file formats using stored procedures. I stumbled accross OPENROWSET, which proves to have more than what i bargined for with being able to support multple file types which include (access, Excel, csv, text) So for this post I am looking [...]]]></description>
				<content:encoded><![CDATA[<p>As I am currently looking into ways in which I could automate dataloading from multiple file formats using stored procedures. I stumbled accross OPENROWSET, which proves to have more than what i bargined for with being able to support multple file types which include (access, Excel, csv, text)</p>
<p>So for this post I am looking into the Excel data loading. I know what you are all thinking, that there are many more better ways out there to load data into a sql table than using OPENROWSET, but I am Limited to using Sql server 2000 and creating a stored procdure like below allows the importer to have more flexibility that if i was to say use a DTP package or other build in import/export functions.</p>
<p>So below is a script for a stored procedure that helps handle the OPENROWSET function. With only 3 parameters to specify, inorder to load an excel file/sheet into a sql table.  </p>
<pre class="brush: sql; ">

create procedure sp_ImportExcelFile            
            (@Source varchar(1000)
            , @SourceSheet varchar (100)
            , @DestinationTable varchar (100))
as

declare @retval int
EXEC master..xp_fileexist @Source, @retval output -- check if file exists
 
if @retval = 0
            begin
                        print &#039;file does not exist.&#039;
                        return
            end
 -- sets default sheet name to Sheet1 if not specfied
if @SourceSheet is null or @SourceSheet = &#039;&#039;
            set @SourceSheet = &#039;[Sheet1$]&#039;  
else
            set @SourceSheet = &#039;[&#039; + ltrim(rtrim(@SourceSheet)) + &#039;$]&#039;

if @DestinationTable is null or @DestinationTable = &#039;&#039;
            set @DestinationTable = substring(@SourceSheet, 2, len(@SourceSheet) - 3) + convert(varchar, getdate(), 126)

exec(&#039;select * into [&#039; + @DestinationTable + &#039;] from openrowset(&#039;&#039;Microsoft.Jet.OLEDB.4.0&#039;&#039;, &#039;&#039;Excel 8.0;HDR=YES;Database=&#039; + @Source + &#039;&#039;&#039;, &#039; + @SourceSheet + &#039;)&#039;)


</pre>
]]></content:encoded>
			<wfw:commentRss>http://garyjmurphy.com/?feed=rss2&#038;p=47</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
