sp-executesql

Performance differences calling sp_executesql with dynamic SQL vs parameters

一世执手 提交于 2019-11-30 23:28:38
Given: CREATE PROCEDURE [dbo].[my_storedproc] @param1 int, @param2 varchar(100) AS <<whatever>> GO Are there known performance differences between these different execution methods?: -- Method #1: declare @param1 int = 1 declare @param2 varchar(100) = 'hello' exec my_storedproc @param1, @param2 -- Method #2: exec my_storedproc @param1=1, @param2='hello' -- Method #3: declare @param1 int = 1 declare @param2 varchar(100) = 'hello' declare @procname nvarchar(100) = N'my_storedproc @param1, @param2' declare @params nvarchar(4000) = N'@param1 int, @param2 varchar(100)' exec sp_executesql @procname,

Create table in by sql statement using executeUpdate in Mysql

点点圈 提交于 2019-11-30 21:16:00
问题 I have the following doGet() : protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MysqlDataSource ds = new MysqlConnectionPoolDataSource(); ds.setServerName("localhost"); ds.setPort(3306); ds.setUser("root"); ds.setPassword(""); try { Connection connection = null ; connection = ds.getConnection(); Statement statement = connection.createStatement(); // create the DB .. statement.executeUpdate("CREATE DATABASE IF NOT EXISTS " +

Performance differences calling sp_executesql with dynamic SQL vs parameters

大憨熊 提交于 2019-11-30 18:22:56
问题 Given: CREATE PROCEDURE [dbo].[my_storedproc] @param1 int, @param2 varchar(100) AS <<whatever>> GO Are there known performance differences between these different execution methods?: -- Method #1: declare @param1 int = 1 declare @param2 varchar(100) = 'hello' exec my_storedproc @param1, @param2 -- Method #2: exec my_storedproc @param1=1, @param2='hello' -- Method #3: declare @param1 int = 1 declare @param2 varchar(100) = 'hello' declare @procname nvarchar(100) = N'my_storedproc @param1,

Workaround for calling table-valued function remotely in SQL Server has even more issues

♀尐吖头ヾ 提交于 2019-11-30 08:48:04
I had a query with a set of parameters that needed to be run multiple times with different parameters, so I wrapped it in a table-valued function. That table valued function needed called from a remote server. Unfortunately, the call fails on the linked server with the error: Msg 4122, Level 16, State 1, Line 29 Remote table-valued function calls are not allowed. Microsoft has acknowledged that "calling a table-valued function remotely" was a feature left out of SQL Server 2008. See: http://connect.microsoft.com/SQLServer/feedback/details/276758/remote-table-valued-function-calls-are-not

Workaround for calling table-valued function remotely in SQL Server has even more issues

家住魔仙堡 提交于 2019-11-29 12:21:00
问题 I had a query with a set of parameters that needed to be run multiple times with different parameters, so I wrapped it in a table-valued function. That table valued function needed called from a remote server. Unfortunately, the call fails on the linked server with the error: Msg 4122, Level 16, State 1, Line 29 Remote table-valued function calls are not allowed. Microsoft has acknowledged that "calling a table-valued function remotely" was a feature left out of SQL Server 2008. See: http:/

Execute sp_executeSql for select…into #table but Can't Select out Temp Table Data

那年仲夏 提交于 2019-11-28 10:40:34
Was trying to select...into a temp Table #TempTable in sp_Executedsql. Not its successfully inserted or not but there Messages there written (359 row(s) affected) that mean successful inserted? Script below DECLARE @Sql NVARCHAR(MAX); SET @Sql = 'select distinct Coloum1,Coloum2 into #TempTable from SPCTable with(nolock) where Convert(varchar(10), Date_Tm, 120) Between @Date_From And @Date_To'; SET @Sql = 'DECLARE @Date_From VARCHAR(10); DECLARE @Date_To VARCHAR(10); SET @Date_From = '''+CONVERT(VARCHAR(10),DATEADD(d,DATEDIFF(d,0,GETDATE()),0)-1,120)+'''; SET @Date_To = '''+CONVERT(VARCHAR(10)

Pass a TABLE variable to sp_executesql

拥有回忆 提交于 2019-11-27 17:17:39
问题 I'm trying to pass a TABLE variable to the sp_executesql procedure: DECLARE @params NVARCHAR(MAX) SET @params = '@workingData TABLE ( col1 VARCHAR(20), col2 VARCHAR(50) )' EXEC sp_executesql @sql, @params, @workingData I get the error: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'TABLE'. I tried omitting the column specification after 'TABLE'. I also tried to declare the table as a variable inside the dynamic SQL. But no luck... Seems to me that TABLE variables aren't

EXEC sp_executesql with multiple parameters

雨燕双飞 提交于 2019-11-27 08:49:32
How to pass the parameters to the EXEC sp_executesql statement correctly? This is what I have now, but i'm getting errors: alter PROCEDURE [dbo].[usp_getReceivedCases] -- Add the parameters for the stored procedure here @LabID int, @RequestTypeID varchar(max), @BeginDate date, @EndDate date AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @statement nvarchar(4000) set @statement = N'select SentToLab, FROM dbo.vEmailSent WHERE SentToLab_ID=@LabID and convert(date,DateSent) >= @BeginDate and CONVERT(date, datesent)

Execute sp_executeSql for select…into #table but Can't Select out Temp Table Data

守給你的承諾、 提交于 2019-11-27 03:43:36
问题 Was trying to select...into a temp Table #TempTable in sp_Executedsql. Not its successfully inserted or not but there Messages there written (359 row(s) affected) that mean successful inserted? Script below DECLARE @Sql NVARCHAR(MAX); SET @Sql = 'select distinct Coloum1,Coloum2 into #TempTable from SPCTable with(nolock) where Convert(varchar(10), Date_Tm, 120) Between @Date_From And @Date_To'; SET @Sql = 'DECLARE @Date_From VARCHAR(10); DECLARE @Date_To VARCHAR(10); SET @Date_From = '''

Entity Framework 4.2 exec sp_executesql does not use indexes (parameter sniffing)

只谈情不闲聊 提交于 2019-11-26 22:50:27
I'm encountering some major performance problems with simple SQL queries generated by the Entity Framework (4.2) running against SQL Server 2008 R2. In some situations (but not all), EF uses the following syntax: exec sp_executesql 'DYNAMIC-SQL-QUERY-HERE', @param1... In other situations is simply executes the raw SQL with the provided parameters baked into the query. The problem I'm encountering is that queries executed with the sp_executesql are ignoring all indexes on my target tables, resulting in an extremely poor performing query (confirmed by examining the execution plan in SSMS). After