sql-server-2012

Group and order with additional exception

偶尔善良 提交于 2019-12-25 07:59:02
问题 I have following table: Declare @YourTable table ([Event] varchar(100),[Start] DateTime,[End] DateTime, [Tag] varchar(25)) Insert Into @YourTable values ('10PIC700422.PV 10-PSV-700073A 10-PSV-700073B','9/9/16 10:44','9/9/16 10:49','Big'), ('10PIC700422.PV 10-PSV-700073A 10-PSV-700073B','9/9/16 10:50','9/9/16 10:51','Small'), ('11PIC41010.PV 11-PSV-401002A 11-PSV-401002B','4/4/16 12:51','4/4/16 13:58','Big'), ('11PIC41010.PV 11-PSV-401002A 11-PSV-401002B','4/4/16 14:04','4/4/16 14:29','Small')

create partition based on the difference between subsequent row indices in sql server 2012

大兔子大兔子 提交于 2019-12-25 07:48:26
问题 I am using SQL Server 2012. I want to create a row_number based on whether the index in subsequent rows are increasing by 1 or more. For example, say I have a table that looks like: event row_index 1 24 2 25 3 26 4 30 5 31 6 42 7 43 8 44 9 45 Then what I want to do is create a column at the end, called seq_ID: event row_index seq_id 1 24 1 2 25 1 3 26 1 4 30 2 5 31 2 6 42 3 7 43 3 8 44 3 9 45 3 basically, the seq_id only chances if the difference between subsequent row indexes is > 1. I have

Deploy SSIS Packages developed using SQL Server Data Tools for Visual Studio 2012

China☆狼群 提交于 2019-12-25 07:33:07
问题 So I have a suite of SSIS packages that we created using Visual Studio 2008 and are currently deployed on a SQL Server 2008R2 instance. However, I would like to upgrade these to 2012 via SQL Server Data Tools for Visual Studio 2012 which is easy enough, however, the company that I work for does not have any plans to upgrade the SQL Server to 2012 any time soon. So is there a way to create SSIS packages using SSIS 2012 and deploy them to a SQL Server 2008R2 instance while maintaining all of

Invoking SSIS Package from WCF service (tcp binding)

喜你入骨 提交于 2019-12-25 07:17:42
问题 I'm trying to invoke an SSIS package in SQL Server 2012 (local installation) via a WCF service hosted in local IIS. The WCF Service is using tcp binding and the IIS app pool is running under NETWORKSERVICE. I'm using a console application to test the WCF service. After the console application calls the WCF service, the WCF service attempts to invoke a SSIS package on the local SQL Server and throws a "System.Data.SqlClient.SqlException: Login failed for user 'MYDOMAIN\MYMACHINENAME$'." The

Combine multiple rows into one “memo” nvarchar(max)

血红的双手。 提交于 2019-12-25 07:17:13
问题 2 tables 1 with clients other with accno information table 1: file, accno <- nvarchar(50) t1, 123a t1, 456a t1, 789a t2, 012b t3, 345c t3, 678c i would like to transfer table 1 to table 2 table 2: file, accno <- nvarchar(max) t1, 123a 456a 789a t2, 012b t3, 345c 678c i can do this is delphi very easy, but itll take forever almost 6 hrs because im filtering close to 300000 records on table 1 is there an sql query that can make this go super fast, even if it takes 5min 回答1: SELECT DISTINCT

Replacing alphabets to zero in any given string in SQL

主宰稳场 提交于 2019-12-25 07:14:17
问题 I'm trying to replace some input strings in a formula to zero value. I was able to do it for certain strings but wasn't able to do for all the strings listed in the below #mathtemp table. I have the input names, I have the formula and all I need to do is just repalce the strings which doesn't have numbers(values) to zero. There is some mistake in the replace statement which I am not able to figure out. I tried using ISNUMERIC to get this done but that doesn't give the required output. Let me

Update row base on distinct, stuff, path query

巧了我就是萌 提交于 2019-12-25 06:47:16
问题 Continue from Combine multiple rows into one "memo" nvarchar(max) SELECT DISTINCT fileref, stuff( ( Select char(13)+char(10) + IsNull( D2.viaccno, '' ) From vi_accno As D2 Where D2.vifileref = A.FileRef For Xml Path(''), type ).value('.', 'nvarchar(max)') , 1, 2, '') As accno FROM vtindex a How do i use the above query to update each accno row on table 1 matching fileref = fileref table 1: id, fileref, client, addr, accno 回答1: Based on given data, I can offer you this: UPDATE t SET accno = p

How to automatically export data from SQL Server 2012 to CSV file?

与世无争的帅哥 提交于 2019-12-25 06:46:56
问题 Hope I dont upset anybody by asking too simple a question! I have a requirement to export data from a SQL Server 2012 table, to a CSV file. This needs to be done either every hour, or ideally if it is possible, whenever a new record is created or an existing record is updated/deleted. The table contains a list of all Sites we maintain. I need to export this CSV file to a particular location, as there is an API from a third party database which monitors this location and imports CSV files from

Select SQL mapping query

做~自己de王妃 提交于 2019-12-25 06:20:33
问题 I use SQL Server 2012 and I have these tables: Table Tb1 ( ID Int, CodeID Int, Value Int ) ID CodeID Value ---------------------- 1 1 10 2 1 14 3 1 5 4 1 25 5 2 12 6 2 17 7 2 4 8 2 10 9 2 6 Table Tb2 ( CodeID Int Value Int ) CodeID Value --------------- 1 25 2 20 I want a query for get records from Tb1 that SUM(Tb1.Value) <= Tb2.Value For example result for above records is : Tb1.ID Tb1.CodeID Tb1.Value UsedValue Tb2.Value -------------------------------------------------------- 1 1 10 10 25