<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Difference Between EXEC and EXECUTE vs EXEC() &#8211; Use EXEC/EXECUTE for SP always</title>
	<atom:link href="http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: AlwaysLearning</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-57577</link>
		<dc:creator>AlwaysLearning</dc:creator>
		<pubDate>Fri, 13 Nov 2009 04:16:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-57577</guid>
		<description>Hi Shelly,

Have you looked at using OPENQUERY or OPENROWSET to access remote data via Linked Servers? This is fast and easy for small volumes of data.

If you&#039;re talking large volumes of data it may be faster (and much easier on the indexes of your destination server) if you use BCP.EXE to dump the data from your source servers in &quot;native format&quot;, transfer it with ftp/scp/rsync, and then BULK INSERT/BCP.EXE to read it back in on the destination server. This is how I used to move millions of rows of IP traffic flows between servers.

Good luck.</description>
		<content:encoded><![CDATA[<p>Hi Shelly,</p>
<p>Have you looked at using OPENQUERY or OPENROWSET to access remote data via Linked Servers? This is fast and easy for small volumes of data.</p>
<p>If you&#8217;re talking large volumes of data it may be faster (and much easier on the indexes of your destination server) if you use BCP.EXE to dump the data from your source servers in &#8220;native format&#8221;, transfer it with ftp/scp/rsync, and then BULK INSERT/BCP.EXE to read it back in on the destination server. This is how I used to move millions of rows of IP traffic flows between servers.</p>
<p>Good luck.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AlwaysLearning</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-57576</link>
		<dc:creator>AlwaysLearning</dc:creator>
		<pubDate>Fri, 13 Nov 2009 04:02:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-57576</guid>
		<description>&gt; SELECT ISNULL(NULL, EXEC(‘SELECT 1′))
&gt; Expected output is 1
&gt; If we run only EXEC(‘SELECT 1′) then it works.
&gt; Please let me know what should I use?

Hi Hitech,

The exec() statement does not work that way. When using exec() with brackets it will not return a scalar value, unlike &quot;exec @Result = someStoredProcedure&quot;

You can still use the result set than comes back from exec(), though, like this:

declare @sqlStr nvarchar(max)
declare @myVar varchar(max)
declare @myTable varchar(max)
declare @totalValue int

set @myTable = &#039;tableName&#039;
set @myVar = &#039;columnName&#039;

set @sqlStr = &#039;select fooBarBaz=sum(&#039; + @myVar + &#039;) from &#039; + @myTable
print @sqlStr
declare @tempTable table (fooBarBaz int)
insert @tempTable exec(@sqlStr)
select @totalValue = fooBarBaz from @tempTable
print @totalValue

As you can see, though, it&#039;s very messy having to go through a temporary table to hold the result set.</description>
		<content:encoded><![CDATA[<p>&gt; SELECT ISNULL(NULL, EXEC(‘SELECT 1′))<br />
&gt; Expected output is 1<br />
&gt; If we run only EXEC(‘SELECT 1′) then it works.<br />
&gt; Please let me know what should I use?</p>
<p>Hi Hitech,</p>
<p>The exec() statement does not work that way. When using exec() with brackets it will not return a scalar value, unlike &#8220;exec @Result = someStoredProcedure&#8221;</p>
<p>You can still use the result set than comes back from exec(), though, like this:</p>
<p>declare @sqlStr nvarchar(max)<br />
declare @myVar varchar(max)<br />
declare @myTable varchar(max)<br />
declare @totalValue int</p>
<p>set @myTable = &#8216;tableName&#8217;<br />
set @myVar = &#8216;columnName&#8217;</p>
<p>set @sqlStr = &#8217;select fooBarBaz=sum(&#8216; + @myVar + &#8216;) from &#8216; + @myTable<br />
print @sqlStr<br />
declare @tempTable table (fooBarBaz int)<br />
insert @tempTable exec(@sqlStr)<br />
select @totalValue = fooBarBaz from @tempTable<br />
print @totalValue</p>
<p>As you can see, though, it&#8217;s very messy having to go through a temporary table to hold the result set.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhruva</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-54541</link>
		<dc:creator>Dhruva</dc:creator>
		<pubDate>Thu, 06 Aug 2009 14:56:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-54541</guid>
		<description>Hi,
i have scheduled the backup of the database and the backup is saved in my local drive C:/backup/,,,,,my problem is that i want the backup to be saved not in the local drive but in the remote computer suppose   the IP address of other machine is   \\10.189.42.123\c$\TEST_BAK_SQL ,,,and the backup is to be scheduled and be saved in the folder   \\10.130.18.123\c$\TEST_BAK_SQL ?????

Thanks in advance....</description>
		<content:encoded><![CDATA[<p>Hi,<br />
i have scheduled the backup of the database and the backup is saved in my local drive C:/backup/,,,,,my problem is that i want the backup to be saved not in the local drive but in the remote computer suppose   the IP address of other machine is   \\10.189.42.123\c$\TEST_BAK_SQL ,,,and the backup is to be scheduled and be saved in the folder   \\10.130.18.123\c$\TEST_BAK_SQL ?????</p>
<p>Thanks in advance&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-53940</link>
		<dc:creator>david</dc:creator>
		<pubDate>Wed, 22 Jul 2009 03:53:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-53940</guid>
		<description>ALTER PROCEDURE [dbo].[SP_TEMANAGMENT_DELETEDOCUMENT_FROM_REPORTS](@ID VARCHAR(25),@EMPID VARCHAR(20),@TABLENAME VARCHAR(50))
AS
BEGIN
declare @SQL VARCHAR(50)
  
SET @SQL=&#039;DELETE &#039;+@TABLENAME+&#039; WHERE profile_id=&#039;+@EMPID+&#039; AND assignment_id= &#039;+@ID
EXEC(@SQL)
 END

whem i am trying to execute it it is giving error
i tried like this
exec  SP_TEMANAGMENT_DELETEDOCUMENT_FROM_REPORTS 400,36,&#039;emp_assignment&#039;</description>
		<content:encoded><![CDATA[<p>ALTER PROCEDURE [dbo].[SP_TEMANAGMENT_DELETEDOCUMENT_FROM_REPORTS](@ID VARCHAR(25),@EMPID VARCHAR(20),@TABLENAME VARCHAR(50))<br />
AS<br />
BEGIN<br />
declare @SQL VARCHAR(50)</p>
<p>SET @SQL=&#8217;DELETE &#8216;+@TABLENAME+&#8217; WHERE profile_id=&#8217;+@EMPID+&#8217; AND assignment_id= &#8216;+@ID<br />
EXEC(@SQL)<br />
 END</p>
<p>whem i am trying to execute it it is giving error<br />
i tried like this<br />
exec  SP_TEMANAGMENT_DELETEDOCUMENT_FROM_REPORTS 400,36,&#8217;emp_assignment&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jr.</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-53513</link>
		<dc:creator>Jr.</dc:creator>
		<pubDate>Tue, 07 Jul 2009 12:48:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-53513</guid>
		<description>exec MASTER..XP_CMDSHELL &#039;Echo Conteudo&gt;&gt;c:\teste.txt&#039;</description>
		<content:encoded><![CDATA[<p>exec MASTER..XP_CMDSHELL &#8216;Echo Conteudo&gt;&gt;c:\teste.txt&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shelly warren</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-53029</link>
		<dc:creator>shelly warren</dc:creator>
		<pubDate>Mon, 15 Jun 2009 18:03:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-53029</guid>
		<description>I am tasked with moving a bunch of data from many servers to one server on a daily basis. 

Basic flow is to pull a set of connection information about various servers, then work through each set making a call to a standard stored procedure which moves and transforms the data to its final resting spot in the reporting database.

I need to keep security in mind and manual configuration, hence the choice to pull connection information for data sets that are maintained and create a connection to each server. Each server is configured and setup the same and contains the same database and fields.

Is there a way to send dynamic connection information into a stored procedure or other object to move the data or am I limited to using a coded (perl, .net, php) script to make the connections and execute the same set of code?</description>
		<content:encoded><![CDATA[<p>I am tasked with moving a bunch of data from many servers to one server on a daily basis. </p>
<p>Basic flow is to pull a set of connection information about various servers, then work through each set making a call to a standard stored procedure which moves and transforms the data to its final resting spot in the reporting database.</p>
<p>I need to keep security in mind and manual configuration, hence the choice to pull connection information for data sets that are maintained and create a connection to each server. Each server is configured and setup the same and contains the same database and fields.</p>
<p>Is there a way to send dynamic connection information into a stored procedure or other object to move the data or am I limited to using a coded (perl, .net, php) script to make the connections and execute the same set of code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hitesh</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-50212</link>
		<dc:creator>Hitesh</dc:creator>
		<pubDate>Mon, 30 Mar 2009 13:28:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-50212</guid>
		<description>Thanks Imran,

I posted simple query so that anybody can understand. My original query is 

SELECT ISNULL(NULL, EXEC (&#039;BEGIN 
EXEC Inferred_CreateDimPatientMember  1 
SELECT PatientKey FROM KeyMapPatientView WHERE CphPatientID = 1 END&#039;))

I know your Tip1 and Tip2 can work but those are not helpful in my case because I want to get an output in single sql statement.

So In my above query I am expecting to have output as PatientKey.


Thanks
Hitesh Savalia.</description>
		<content:encoded><![CDATA[<p>Thanks Imran,</p>
<p>I posted simple query so that anybody can understand. My original query is </p>
<p>SELECT ISNULL(NULL, EXEC (&#8216;BEGIN<br />
EXEC Inferred_CreateDimPatientMember  1<br />
SELECT PatientKey FROM KeyMapPatientView WHERE CphPatientID = 1 END&#8217;))</p>
<p>I know your Tip1 and Tip2 can work but those are not helpful in my case because I want to get an output in single sql statement.</p>
<p>So In my above query I am expecting to have output as PatientKey.</p>
<p>Thanks<br />
Hitesh Savalia.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-50135</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Sat, 28 Mar 2009 06:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-50135</guid>
		<description>@Hitesh

how about this ?
SELECT ISNULL(NULL, 1)

Output : 1

-- Why dont you try any one of this, 

Tip 1:

if exists ( select cola from table1 where cola is null)
begin
set @sql = execute dynamic sql parameter, with output parameter 

set cola = output value from above dynamic sql
end

Tip 2 :
 select 
 case when cola is null then another_value 
from table1


Please post complete question, what is your requirement, what is that you are trying to execute ?

~IM</description>
		<content:encoded><![CDATA[<p>@Hitesh</p>
<p>how about this ?<br />
SELECT ISNULL(NULL, 1)</p>
<p>Output : 1</p>
<p>&#8211; Why dont you try any one of this, </p>
<p>Tip 1:</p>
<p>if exists ( select cola from table1 where cola is null)<br />
begin<br />
set @sql = execute dynamic sql parameter, with output parameter </p>
<p>set cola = output value from above dynamic sql<br />
end</p>
<p>Tip 2 :<br />
 select<br />
 case when cola is null then another_value<br />
from table1</p>
<p>Please post complete question, what is your requirement, what is that you are trying to execute ?</p>
<p>~IM</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hitesh</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-50125</link>
		<dc:creator>Hitesh</dc:creator>
		<pubDate>Fri, 27 Mar 2009 20:36:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-50125</guid>
		<description>Hi,
            I have a very simple query and it seems valid to me but it is not working and giving a syntax error. I looked on different sites but I couldn’t find anything. And finally have decided to ask you.


SELECT ISNULL(NULL, EXEC(&#039;SELECT 1&#039;))

Expected output is 1

If we run only EXEC(&#039;SELECT 1&#039;) then it works.

 
Please let me know what should I use?
 

 
Thanks,
Hitesh Savalia, MCAD</description>
		<content:encoded><![CDATA[<p>Hi,<br />
            I have a very simple query and it seems valid to me but it is not working and giving a syntax error. I looked on different sites but I couldn’t find anything. And finally have decided to ask you.</p>
<p>SELECT ISNULL(NULL, EXEC(&#8216;SELECT 1&#8242;))</p>
<p>Expected output is 1</p>
<p>If we run only EXEC(&#8216;SELECT 1&#8242;) then it works.</p>
<p>Please let me know what should I use?</p>
<p>Thanks,<br />
Hitesh Savalia, MCAD</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sharmin Jose</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-46027</link>
		<dc:creator>Sharmin Jose</dc:creator>
		<pubDate>Tue, 27 Jan 2009 17:27:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-46027</guid>
		<description>Hi,

To assign values dynamically we need to use sp_executesql procedure. The N&#039; is mandatory as the parameter should be converted to NText.

USE [MyDB]
GO
/****** Object:  StoredProcedure [dbo].[selectedSortedOutput]    Script Date: 01/27/2009 11:02:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[selectedSortedOutput](@sortColname nvarchar(50))
As
declare 
	@FName nvarchar(50),
	@Sql nvarchar(1500);
begin
	set @Sql = &#039;select @FName=FirstName from Customer order by &#039; + @sortColname;
	exec sp_executesql @Sql,N&#039;@FName nvarchar(50) OUTPUT&#039;, @FName OUTPUT; 
	Print @FName;
end;</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>To assign values dynamically we need to use sp_executesql procedure. The N&#8217; is mandatory as the parameter should be converted to NText.</p>
<p>USE [MyDB]<br />
GO<br />
/****** Object:  StoredProcedure [dbo].[selectedSortedOutput]    Script Date: 01/27/2009 11:02:27 ******/<br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
ALTER procedure [dbo].[selectedSortedOutput](@sortColname nvarchar(50))<br />
As<br />
declare<br />
	@FName nvarchar(50),<br />
	@Sql nvarchar(1500);<br />
begin<br />
	set @Sql = &#8217;select @FName=FirstName from Customer order by &#8216; + @sortColname;<br />
	exec sp_executesql @Sql,N&#8217;@FName nvarchar(50) OUTPUT&#8217;, @FName OUTPUT;<br />
	Print @FName;<br />
end;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vijay Jaiswal</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45568</link>
		<dc:creator>Vijay Jaiswal</dc:creator>
		<pubDate>Tue, 13 Jan 2009 06:45:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45568</guid>
		<description>You should use where clause like this

@whereclause =&#039; And username=&#039;&#039;admin&#039;&#039;&#039;

In above statement, multiple single quotes are used.</description>
		<content:encoded><![CDATA[<p>You should use where clause like this</p>
<p>@whereclause =&#8217; And username=&#8221;admin&#8221;&#8217;</p>
<p>In above statement, multiple single quotes are used.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahul Singh</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45505</link>
		<dc:creator>Rahul Singh</dc:creator>
		<pubDate>Fri, 09 Jan 2009 19:32:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45505</guid>
		<description>ALTER PROCEDURE [dbo].[GetByWhereClause] 
	
	@tablename varchar(50),
	@whereclause varchar(max)
AS
BEGIN
	
DECLARE @sqlquery varchar(5000)

SET @sqlquery = &#039;SELECT * FROM &#039;+@tablename+&#039; WHERE 1=1 &#039;+@whereclause

EXEC(@sqlquery)

END

Suppose,
@tablename = BuyerMaster
@whereclause =  And username=admin

It give an Error &quot;Invalid column name admin&quot;

How can I put admin in single quotes as I am getting the values from ASP.NET page.

Please Help Me, 
Please.

Thanking You,
Rahul</description>
		<content:encoded><![CDATA[<p>ALTER PROCEDURE [dbo].[GetByWhereClause] </p>
<p>	@tablename varchar(50),<br />
	@whereclause varchar(max)<br />
AS<br />
BEGIN</p>
<p>DECLARE @sqlquery varchar(5000)</p>
<p>SET @sqlquery = &#8216;SELECT * FROM &#8216;+@tablename+&#8217; WHERE 1=1 &#8216;+@whereclause</p>
<p>EXEC(@sqlquery)</p>
<p>END</p>
<p>Suppose,<br />
@tablename = BuyerMaster<br />
@whereclause =  And username=admin</p>
<p>It give an Error &#8220;Invalid column name admin&#8221;</p>
<p>How can I put admin in single quotes as I am getting the values from ASP.NET page.</p>
<p>Please Help Me,<br />
Please.</p>
<p>Thanking You,<br />
Rahul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahul Singh</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45504</link>
		<dc:creator>Rahul Singh</dc:creator>
		<pubDate>Fri, 09 Jan 2009 19:32:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45504</guid>
		<description>ALTER PROCEDURE [dbo].[GetByWhereClause] 
	
	@tablename varchar(50),
	@whereclause varchar(max)
AS
BEGIN
	
DECLARE @sqlquery varchar(5000)

SET @sqlquery = &#039;SELECT * FROM &#039;+@tablename+&#039; WHERE 1=1 &#039;+@whereclause

EXEC(@sqlquery)

END

Suppose,
@tablename = &quot;BuyerMaster&quot;
@whereclause = &quot; And username=admin&quot;.

It give an Error &quot;Invalid column name admin&quot;

How can I put admin in single quotes as I am getting the values from ASP.NET page.

Please Help Me, 
Please.

Thanking You,
Rahul</description>
		<content:encoded><![CDATA[<p>ALTER PROCEDURE [dbo].[GetByWhereClause] </p>
<p>	@tablename varchar(50),<br />
	@whereclause varchar(max)<br />
AS<br />
BEGIN</p>
<p>DECLARE @sqlquery varchar(5000)</p>
<p>SET @sqlquery = &#8216;SELECT * FROM &#8216;+@tablename+&#8217; WHERE 1=1 &#8216;+@whereclause</p>
<p>EXEC(@sqlquery)</p>
<p>END</p>
<p>Suppose,<br />
@tablename = &#8220;BuyerMaster&#8221;<br />
@whereclause = &#8221; And username=admin&#8221;.</p>
<p>It give an Error &#8220;Invalid column name admin&#8221;</p>
<p>How can I put admin in single quotes as I am getting the values from ASP.NET page.</p>
<p>Please Help Me,<br />
Please.</p>
<p>Thanking You,<br />
Rahul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pg</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45402</link>
		<dc:creator>pg</dc:creator>
		<pubDate>Tue, 06 Jan 2009 12:38:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45402</guid>
		<description>Hi,

how to fill SQL varaible if using a statement inside in EXEC command line eg.

DECALRE @Value bigint
SET @Value = EXEC (&#039;SELECT COUNT(ID) FROM Table&#039;)
SELECT @Value

Is this is possible in this way to capture return value from concatenated statement...or there is other way to do it.

in short what i want is to fill up a variable by return value from exec statement and not from simple select query statement.

thanks if u help me...</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>how to fill SQL varaible if using a statement inside in EXEC command line eg.</p>
<p>DECALRE @Value bigint<br />
SET @Value = EXEC (&#8216;SELECT COUNT(ID) FROM Table&#8217;)<br />
SELECT @Value</p>
<p>Is this is possible in this way to capture return value from concatenated statement&#8230;or there is other way to do it.</p>
<p>in short what i want is to fill up a variable by return value from exec statement and not from simple select query statement.</p>
<p>thanks if u help me&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dirk-Jan</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45232</link>
		<dc:creator>Dirk-Jan</dc:creator>
		<pubDate>Wed, 31 Dec 2008 13:38:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-45232</guid>
		<description>Hi,

How can I execute a stored procedure stored on instance A on instance B? The Variable is a database name of instance B.

Can somebody help me?

Thx</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>How can I execute a stored procedure stored on instance A on instance B? The Variable is a database name of instance B.</p>
<p>Can somebody help me?</p>
<p>Thx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anup</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44880</link>
		<dc:creator>Anup</dc:creator>
		<pubDate>Wed, 17 Dec 2008 12:13:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44880</guid>
		<description>Hi guys,
I have one problem regarding exec.
Can anyone tell me that how to use exec() inside the function or procedure.

Thanx in advance.</description>
		<content:encoded><![CDATA[<p>Hi guys,<br />
I have one problem regarding exec.<br />
Can anyone tell me that how to use exec() inside the function or procedure.</p>
<p>Thanx in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44803</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Mon, 15 Dec 2008 07:33:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44803</guid>
		<description>Ideally, 

You should not need GO Statement in EXECUTE.

If you need something like that use semi-comma.

Regards,
Pinal Dave ( http://blog.sqlauthority.com )</description>
		<content:encoded><![CDATA[<p>Ideally, </p>
<p>You should not need GO Statement in EXECUTE.</p>
<p>If you need something like that use semi-comma.</p>
<p>Regards,<br />
Pinal Dave ( <a href="http://blog.sqlauthority.com" rel="nofollow">http://blog.sqlauthority.com</a> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gurudatt Nayak</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44801</link>
		<dc:creator>Gurudatt Nayak</dc:creator>
		<pubDate>Mon, 15 Dec 2008 07:17:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44801</guid>
		<description>Hi,

How to use a GO Statement in a dynamic SQL Query.

declare @strsql varchar(max)

SELECT @strsql = &#039; Stmt1 
GO
Stmt2
GO&#039;

EXECUTE (@strsql)


This gives an error : Incorrect syntax near GO.


Regards,

Gurudatt</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>How to use a GO Statement in a dynamic SQL Query.</p>
<p>declare @strsql varchar(max)</p>
<p>SELECT @strsql = &#8216; Stmt1<br />
GO<br />
Stmt2<br />
GO&#8217;</p>
<p>EXECUTE (@strsql)</p>
<p>This gives an error : Incorrect syntax near GO.</p>
<p>Regards,</p>
<p>Gurudatt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44391</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 25 Nov 2008 17:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-44391</guid>
		<description>&gt;SET @sqlStr = ‘Select @totalValue=SUM(’ + @myVar + ‘) from ‘ + @myTable
&gt;
&gt;Exec(N’ SET NOCOUNT ON’ + @sqlStr)
If you are going to use any variables inside EXEC() you need to declare them inside EXEC().

&gt;EXEC (’Use pubs’)
That command would change the database within the EXEC() command. Any additional commands would use the pubs database.

Basically the command executed within EXEC() has its own context.</description>
		<content:encoded><![CDATA[<p>&gt;SET @sqlStr = ‘Select @totalValue=SUM(’ + @myVar + ‘) from ‘ + @myTable<br />
&gt;<br />
&gt;Exec(N’ SET NOCOUNT ON’ + @sqlStr)<br />
If you are going to use any variables inside EXEC() you need to declare them inside EXEC().</p>
<p>&gt;EXEC (’Use pubs’)<br />
That command would change the database within the EXEC() command. Any additional commands would use the pubs database.</p>
<p>Basically the command executed within EXEC() has its own context.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Janet</title>
		<link>http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-42062</link>
		<dc:creator>Janet</dc:creator>
		<pubDate>Tue, 26 Aug 2008 17:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/13/sql-server-difference-between-exec-and-execute-vs-exec-use-execexecute-for-sp-always/#comment-42062</guid>
		<description>Why this doesnot work?

EXEC (&#039;Use pubs&#039;)

The command is successfull but the database setting didnot change when I execute in Query Analyzer?</description>
		<content:encoded><![CDATA[<p>Why this doesnot work?</p>
<p>EXEC (&#8216;Use pubs&#8217;)</p>
<p>The command is successfull but the database setting didnot change when I execute in Query Analyzer?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
