sql-server-2005

Parameter Sniffing (or Spoofing) in SQL Server

时间秒杀一切 提交于 2019-12-16 20:12:41
问题 A while ago I had a query that I ran quite a lot for one of my users. It was still being evolved and tweaked but eventually it stablised and ran quite quickly, so we created a stored procedure from it. So far, so normal. The stored procedure, though, was dog slow. No material difference between the query and the proc, but the speed change was massive. [Background, we're running SQL Server 2005.] A friendly local DBA (who no longer works here) took one look at the stored procedure and said

Nested stored procedures containing TRY CATCH ROLLBACK pattern?

蓝咒 提交于 2019-12-16 19:53:25
问题 I'm interested in the side effects and potential problems of the following pattern: CREATE PROCEDURE [Name] AS BEGIN BEGIN TRANSACTION BEGIN TRY [...Perform work, call nested procedures...] END TRY BEGIN CATCH ROLLBACK TRANSACTION RAISERROR [rethrow caught error using @ErrorNumber, @ErrorMessage, etc] END CATCH END To the best of my understanding this pattern is sound when used with a single procedure - the procedure will either complete all of its statements without error, or it will

error in creating a temp table using dynamic sql

早过忘川 提交于 2019-12-16 18:05:20
问题 declare @TableName nvarchar(max) set @TableName='addresses' DECLARE @sql NVARCHAR(MAX) set @sql= 'create table #tempadd ( ' SELECT @sql=@sql + STUFF( -- Remove first comma ( SELECT ', ' + column_name+' '+ case when DATA_TYPE='varchar' then DATA_TYPE +'(500)' else DATA_TYPE end FROM -- create comma separated values ( SELECT column_name,DATA_TYPE FROM information_schema.columns where table_name = @TableName --Your query here ) AS T FOR XML PATH('') ) ,1,1,'') set @sql =@sql+' ) ' print @sql -

i get an error when creating a variable and specifing the collation in sql server 2005

心不动则不痛 提交于 2019-12-16 18:04:31
问题 when i tried this: DECLARE @var nvarchar(500) collate Arabic_BIN i got that: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'collate'. that is the full code, it works, i do not know how but the person who give it to me have used it successfully CREATE FUNCTION fn_RemoveTashkeel (@InputString nvarchar(2300) ) RETURNS nvarchar(2300) AS BEGIN DECLARE @OutputString nvarchar(2300) COLLATE Arabic_BIN DECLARE @TashkeelChr char(8) COLLATE Arabic_BIN DECLARE @feed int SET

i get an error when creating a variable and specifing the collation in sql server 2005

强颜欢笑 提交于 2019-12-16 18:04:22
问题 when i tried this: DECLARE @var nvarchar(500) collate Arabic_BIN i got that: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'collate'. that is the full code, it works, i do not know how but the person who give it to me have used it successfully CREATE FUNCTION fn_RemoveTashkeel (@InputString nvarchar(2300) ) RETURNS nvarchar(2300) AS BEGIN DECLARE @OutputString nvarchar(2300) COLLATE Arabic_BIN DECLARE @TashkeelChr char(8) COLLATE Arabic_BIN DECLARE @feed int SET

Join characters using SET BASED APPROACH (Sql Server 2005)

删除回忆录丶 提交于 2019-12-14 04:26:14
问题 I have a table where the data are like Data a b c I need to write a SQL Query to bring the following output Data abc Note:~ The number of characters are not constrained to 3. I have solved using while loop. But I have to do it using set based approach.So how can I join those characters? I tried using COALESCE but no luck Please help me Edit: I cannot use any function or CLR. It needs to be entirely in 1 SQL. FOR XML PATH is a good choice but it is showing some link. Actually I have never used

Subqueries are not allowed after VALUES?

自作多情 提交于 2019-12-14 04:23:06
问题 INSERT INTO t_MT_User (ID, Badge, Name, Scope, comp_code, dept_code, [status]) VALUES ((SELECT MAX(ID) + 1 FROM t_MT_User), @userBadgeNumber, @userName, @userScope, @companyCode, @departmentCode, 1) This query throws the following error: Subqueries are not allowed in this context. Only scalar expressions are allowed. If I change VALUES to SELECT , I get another error instead: INSERT INTO t_MT_User (ID, Badge, Name, Scope, comp_code, dept_code, [status]) SELECT ((SELECT MAX(ID) + 1 FROM t_MT

How to load data from SQL Server to SAP BW using SSIS

為{幸葍}努か 提交于 2019-12-14 04:19:52
问题 I would like to load data from SQL server to SAP BW using SSIS. Could some one help me on it how can i do it. Currently i am using sql server 2005. 回答1: Why would you use SSIS for that? I would recommend either load using SAP BW standard anyDB source system or using BO Data Services. Both do it natively and well. If you insist, look at: https://theobald-software.com/en/xtract-is-productinfo.html They have the following feature: Xtract IS BW Loader With the Xtract IS BW Loader data target, you

SQL Server performance issue with parameters

限于喜欢 提交于 2019-12-14 04:19:29
问题 There is a performance issue with a SQL query. This is my query declare @siteId int, @totalCount int SELECT @totalCount = COUNT(DISTINCT pro.product_id) FROM product AS pro INNER JOIN product_to_category AS proCat ON pro.product_id = proCat.product_id INNER JOIN product_to_vendor proVen ON pro.product_id = proVen.product_id WHERE pro.site_id = @siteId AND pro.product_type <> 3 print @totalCount It is take 6 seconds to execute.. when I remove parameters as follows @totalCount int SELECT

Triggers and disabling “row(s) affected” message

佐手、 提交于 2019-12-14 04:19:00
问题 I have a trigger type INSTEAD OF Insert, Update. It looks something like below: IF EXISTS(some select staement) updade set where ELSE IF (some other select staement) insert values ELSE--(3) RAISERROR ('msg',16,1) RETURN; SET NOCOUNT ON; The issue is that in 3rd - "else" option I would like to show only error message without any "row(s) affected" message. SET NOCOUNT ON dosen't work for me. I've already tried different configurations, put this with and without return. I was putted it