TSql Trigger needs to fire only on columns whose values have changed

I wrote a trigger that needs to do some different work on a table based on which columns in a row actually updated. I accomplished this using IF UPDATE(column-name) That part works fine. It turns out, however, that there are other parts of the code that update rows by setting every single value whether the […]

Node.js MSSQL tedius ConnectionError: Failed to connect to localhost:1433 – connect ECONNREFUSED

I am trying to connect to MSSQL 2012 using NodeJS with the mssql connection interface. When attempting to connect I get the following error: { [ConnectionError: Failed to connect to localhost:1433 – connect ECONNREFUSED] name: ‘ConnectionError’, message: ‘Failed to conncet to localhost:1433 – connect ECONNREFUSED’, code: ‘ESOCKET’ } Any ideas on how to fix this?

Get the most recent Friday's date SQL

I’m trying to get the most recent Friday in SQL Server 2008. I have this. It gets the beginning of the week (monday) then subtracts 3 days to get Friday. declare @recentFriday datetime = DATEADD(ww, DATEDIFF(dd,0,GETDATE()), 0)-3 When this is run during the week, it gets last Friday’s date which is correct. But when run […]

Selecting every nth row from SQL Server 2008 query result where table does not have row id column

I feel so close… I think my problem is how I’m using the MOD function combined with the ROW_NUMBER() function, but I don’t understand what I’m doing wrong. I’m using the ROW_NUMBER() function because I need a way to select every “nth” row. I’ve read the other pages about this (I used them to create […]

How to fix Visual Studio's error “This server version is not supported…” for SQL Server 2012

I recently installed Visual Studio 2010 and SQL Server 2012 on a Windows Server 2008 R2 machine – (including all updates/Service Packs). When attempting to work on a SQL Server database from within Visual Studio, VS throws the following error: This server version is not supported. Only servers up to Microsoft SQL Server 2008 are […]

SQL Server 2008 Transaction, rollback required?

I have a stored procedure that has a BEGIN TRANSACTION and COMMIT TRANSACTION statement. Within the transaction is a select query WITH(XLOCK, ROWLOCK). The transaction can potentially fail due to some calculations that cause an arithmetic overflow error if out of bounds values are supplied. This error would happen before any insert/update statements. My question […]

Visual Studio 2010 – Database Project with imported database fails to build

I’m looking at the Database Project in VS2010, the idea being that I want something I can use to keep track of the database schema (in source control) and the ability to generate “new install” scripts, and change scripts. When I create a new database project wizard and import my existing database schema, it won’t […]

Intermittent SQL Exception – network-related or instance-specific error

We have a very strange intermittent issue which has started coming up over the last month or so whereby some connections to mssql server fail with the error: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance […]

Converting NVARCHAR(255) to DATE

I’m trying to transfer some old SQL Server data using Excel into SQL Server. It seems that Import/Export Data application automatically sets most data columns to NVARCHAR(255). Problem I have, is one of my columns is supposed to be a DATE type, but all data in it looks like this 18.08.2000 14:48:15. So, when I […]

Numeric sort order for strings containing same-length integers under all collations

Is it safe to assume that all collations in SQL Server will give the “expected” (i.e. numeric) sort order on strings containing integers of the same length? For example, assuming that @text contains just non-negative integers ([0-9]+), would the following snippet work for ensuring that the value does not overflow the int range, or might […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.