sql-server-2005

sql-server-2005: How to perform a split on a pipe delimited string variable?

社会主义新天地 提交于 2020-01-15 20:22:19
问题 i have simple data coming in like this: declare @string varchar(500) = "val1|val2|val3" how could i split this out into a cte or something similar so i could user it in a later query: select col1 from table where col2 = @valFromCTE 回答1: This is a helpful and simple way to query a delimited string as if it were a table. Taken from: http://www.mindsdoor.net/SQLTsql/ParseCSVString.html if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_ParseCSVString]') and xtype in (N'FN',

sql-server-2005: How to perform a split on a pipe delimited string variable?

浪子不回头ぞ 提交于 2020-01-15 20:16:36
问题 i have simple data coming in like this: declare @string varchar(500) = "val1|val2|val3" how could i split this out into a cte or something similar so i could user it in a later query: select col1 from table where col2 = @valFromCTE 回答1: This is a helpful and simple way to query a delimited string as if it were a table. Taken from: http://www.mindsdoor.net/SQLTsql/ParseCSVString.html if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_ParseCSVString]') and xtype in (N'FN',

Calculate all “Sundays,Mondays…Saturdays” between two days in SQL Server

ぃ、小莉子 提交于 2020-01-15 15:58:08
问题 I want to calculate total say Sundays,Mondays...Saturdays between two days. I want a do it in a select query because that is mandatory according to the situation where I'm currently working. I have some working code where I'm able to calculate all sundays but not working in case of mondays DECLARE @StartDate DATE = '2011-10-01', @EndDate DATE = '2011-10-31' SELECT DayCount = count(* ) FROM (SELECT TOP ( datediff(DAY,@StartDate,@EndDate) + 1 ) [Date] = dateadd(DAY,ROW_NUMBER() OVER(ORDER BY c1

What's the best way to ensure referential integrity on a replicated database?

此生再无相见时 提交于 2020-01-15 11:51:51
问题 Using SQL SERVER 2005, I have a couple of questions on Replication and referential integrity. 1) Does Replication handle referential integrity? 2) If I do an Insert to Parent table and then to Insert to Child table, in one transaction, on Source DB - will Replicated DB also behave in the same manner? I.e. In Replicated DB record must be present in Master table, before it is referenced in child table? Thanks 回答1: Assuming replication is transactional and you have referential integrity on your

SQL Server 2005 Run a stored procedure via SSIS using GETDATE() as a Parameter

£可爱£侵袭症+ 提交于 2020-01-15 11:37:20
问题 I've been searching for an answer to this and I can't find it. I want to set up an SSIS package using Visual Studio 2005 and SQL Server 2005 that will send today's date (GETDATE())as the parameter to a stored procedure. I can find how to send a parameter, but not how to declare that parameter to be GETDATE(). Is this even possible? 回答1: If you need a constantly evaluating time, like GETDATE() then, create a Variable in SSIS called GetDate with a Data Type of DateTime. Right click and on the

SQL Server 2005 Run a stored procedure via SSIS using GETDATE() as a Parameter

泪湿孤枕 提交于 2020-01-15 11:37:10
问题 I've been searching for an answer to this and I can't find it. I want to set up an SSIS package using Visual Studio 2005 and SQL Server 2005 that will send today's date (GETDATE())as the parameter to a stored procedure. I can find how to send a parameter, but not how to declare that parameter to be GETDATE(). Is this even possible? 回答1: If you need a constantly evaluating time, like GETDATE() then, create a Variable in SSIS called GetDate with a Data Type of DateTime. Right click and on the

Grouping sets: display subtotals in other specific column?

时光怂恿深爱的人放手 提交于 2020-01-15 11:35:11
问题 it is possible to display subtotals in other specific column? SELECT deptno,empno,SUM(sal) as sum_salary FROM emp_test 3 GROUP BY GROUPING SETS ((DeptNo,Empno),(DeptNo),()) Actually I get this result: DEPTNO EMPNO SUM(SAL) 10 7782 20000 10 7839 10000 10 30000 20 7566 5950 20 7788 6000 20 7902 6000 20 17950 30 7698 20000 30 7699 20000 30 40000 87950 How can I get that? : DEPTNO EMPNO SUM(SAL) Subtotals 10 7782 20000 10 7839 10000 10 30000 20 7566 5950 20 7788 6000 20 7902 6000 20 17950 30 7698

convert date to spanish in sql

China☆狼群 提交于 2020-01-15 11:08:42
问题 I am running a report with multiple fields in english. I have 2 date fields at the end of the report, one has to be in English and the other in Spanish. The format the date needs to be in is ie November 1, 2012. I need the spanish to be Novembre 1, 2012. I cannot get the last field of the report to produce in spanish. I am running in sql server 2005. 回答1: Maybe is cumbersome, but I don't see how to do it on an easier way. First, create a function. This function will make use of system view

convert date to spanish in sql

余生长醉 提交于 2020-01-15 11:05:03
问题 I am running a report with multiple fields in english. I have 2 date fields at the end of the report, one has to be in English and the other in Spanish. The format the date needs to be in is ie November 1, 2012. I need the spanish to be Novembre 1, 2012. I cannot get the last field of the report to produce in spanish. I am running in sql server 2005. 回答1: Maybe is cumbersome, but I don't see how to do it on an easier way. First, create a function. This function will make use of system view

Conditional Data Flow Based on Source CSV Filename

吃可爱长大的小学妹 提交于 2020-01-15 10:15:54
问题 I have a series of data that is produced by state and information type. For each state I have, for example, 3 files that have an identifier in the file name to tell me which information group it is for. The data in these files consists of rows of data that have varying lengths depending on the file type. Type 1 always has 245 comma separated values, Type 2 has 215, Type 3 has 300. I have 3 separate SSIS 2005 packages set up to import this data but I was wondering if there is a way to do this