sql-server-2012

Applying LAG() to multiple rows with a null value

穿精又带淫゛_ 提交于 2019-12-25 00:29:42
问题 Given: with m as ( select 1 ID, cast('03/01/2015' as datetime) PERIOD_START, cast('3/31/2015' as datetime) PERIOD_END union all select 1 ID, '04/01/2015', '4/28/2015' union all select 1 ID, '05/01/2015', '5/31/2015' union all select 1 ID, '06/01/2015', '06/30/2015' union all select 1 ID, '07/01/2015', '07/31/2015' ) , a as ( SELECT 1 ID, cast('2015-03-13 14:17:00.000' as datetime) AUDIT_TIME, 'READ [2]' STATUS UNION ALL SELECT 1 ID, '2015-04-27 15:51:00.000' AUDIT_TIME, 'HELD [2]' STATUS

How to tweak WHERE clause to select all records without Premium = 0 when passing NULL as a parameter in SQL statement

拈花ヽ惹草 提交于 2019-12-25 00:23:20
问题 The result should return: If @reasonID = 1 I need to select only policies that have reasonID = 211 If @reasonID = 2 I need to select only policies that have reasonID <> 211 including reasonID IS NULL If @reasonID = NULL I need to select all policies including NULL and Premium <> 0 The below example works for @reasonID = 1 and @reasonID = 2 : @reasonID = 1 @reasonID = 2 But how can I tweak the WHERE clause to select all rows when @reasonID = NULL ? Because it returns policies that have Premium

SQL Server 2012: dynamic SQL limitation ( > 4000 chars) (split)

帅比萌擦擦* 提交于 2019-12-24 23:20:11
问题 I have this dynamic SQL in a stored procedure: Declare @template nvarchar(max) Declare @publishdetails nvarchar(max) set @publishdetails= ',B.[PublishedBy]=suser_name(), B.[PublishedDate]=GETDATE() ' set @template='if NOT EXISTS(select * from ' +@DestinationDB+ '.[CLs] where id='+ str(@slid)+') insert into ' +@DestinationDB+ '.CLs (id,slid,slversion) VALUES ( '+ str(@id)+','+ str(@slid)+','+str(@slversion)+') update B set B.[Clientid]=A.clientid, --......... B.[CreatedDate] = A.CreatedDate, B

Calculate Final outcome based on Results/ID

北慕城南 提交于 2019-12-24 23:15:19
问题 For a Table T1 +----------+-----------+-----------------+ | PersonID | Date | Employment | +----------+-----------+-----------------+ | 1 | 2/28/2017 | Stayed the same | | 1 | 4/21/2017 | Stayed the same | | 1 | 5/18/2017 | Stayed the same | | 2 | 3/7/2017 | Improved | | 2 | 4/1/2017 | Stayed the same | | 2 | 6/1/2017 | Stayed the same | | 3 | 3/28/2016 | Improved | | 3 | 5/4/2016 | Improved | | 3 | 4/19/2017 | Worsened | | 4 | 5/19/2016 | Worsened | | 4 | 2/16/2017 | Improved | +----------+-

How to track changes in database when there is something changes?

一个人想着一个人 提交于 2019-12-24 22:55:49
问题 Supposed that i have all privileges on a database and there is an application using that database. How to know which tables, which columns have changes in database when I do something in the screen. This is for Windows and SQL Server 2012. We don't have database structure document. That's why i need this to trace this 回答1: You can create a trigger which will insert column name, old values and new values in a audit table as shown below. CREATE TABLE [dbo].[NewAuditLog]( [Type] [char](1) NULL,

Why is Linq query setting my Arithabort options to false?

走远了吗. 提交于 2019-12-24 22:32:28
问题 I have code like this: using (var db = new MyDataContext()) { db.ExecuteStoreCommand("Set Arithabort on"); var q = AFairlyComplexQuery(db); // returns an IQueryable<> var result = q.ToList(); // Line 4 return result; } I was finding that this query was timing out. I ran SQL Profiler and grabbed the SQL and ran it in SSMS, and it came back in 7 seconds. From past experience, I've learned that this is invariably being caused by the Arithabort option being set to 0 , which is why I run that

Bulk insert, Cannot bulk load. Unknown version of format file

跟風遠走 提交于 2019-12-24 22:19:49
问题 I'm having problems importing data exported using a more recent version of the bcp utility. I need my exported data to be compatible with SQL server 2012. It is my understanding that I need to add the -V110 option when exporting data. However, even if I add the -V110 to the bcp command I always get version 12.0 (which is my bcp version) on the FMT file. Here is a sample of my bcp call: bcp [DB].[dbo].[Table1] format nul -c -f "E:\TMP\DATA\Table1.FMT" -V110 -S [SERVER] -t , -T Does anybody

SQL join using USING: <column name> is not a recognized table hints option

断了今生、忘了曾经 提交于 2019-12-24 21:13:40
问题 I have the following JOIN: SELECT * FROM tableA INNER JOIN tableB USING (commonColumn) I get an error: "commonColumn" is not a recognized table hints option. If it is intended as a parameter to a table-valued function or to the CHANGETABLE function, ensure that your database compatibility mode is set to 90. The following instead works: SELECT * FROM tableA INNER JOIN tableB ON tableA.commonColumn = tableB.commonColumn The compatibility level in my case is set to 100 (SQL Server 2008), while,

SELECT INTO ##temptable from dynamic @sql

半城伤御伤魂 提交于 2019-12-24 20:45:40
问题 SQL Server 2012. There is a table with sql statements, maintained by developers. CREATE TABLE t ( id INT PRIMARY KEY CLUSTERED NOT NULL IDENTITY(1, 1) , sql_statement NVARCHAR(MAX) NOT NULL , recipient NVARCHAR(MAX) NOT NULL ); INSERT INTO t SELECT 'select 1 as one, 2 as two, 3 as three' , 'some-email-address@host.com' Every now and then, an automated process kicks-in and executes one of the statements, checks if it returned any rows and if it did, emails them. Important bit is, the process

SQL Server repository for informatica powercenter

对着背影说爱祢 提交于 2019-12-24 17:57:39
问题 I have a powercenter 9.1 installation on windows server 2008 R2. The repository is on the same box, hosted on sql server 2012. I have configured a new user (with sql server authentication) and have the repo db owned by that user. (it has the owner role) The core problem : I am not able to run a simple test workflow on this setup. Here's what I have been trying The windows firewall has been taken down now for about an hour or so. The repository service and integration service are running in