SQL Same ID Populated in Multiple Rows with Different Column Values Populated–Need One ID in One Row

I have a table like following: ID Col1 Col2 Col3 Col4 001 A 001 B 001 C 001 D 002 X 002 Y I want the result like the following: ID Col1 Col2 Col3 Col4 001 A B C D 002 X Y The challenge is the number of columns is unknown, maybe this it […]

sp_executesql inside Try & Catch

Begin Try Declare @SQL NVarchar(Max)=’Exec [MyLinkedServer].master.dbo.sp_executesql N”Drop Table [tempdb].dbo.[T1]”’; Print @SQL; Exec master.dbo.sp_executesql @SQL; End Try Begin Catch Print Error_Message() End Catch The above script fails when the table T1 doesn’t exist in MyLinkedServer instead of being directed to Catch section. What do I miss? Just to be clear: the original procedure constructs the @SQL […]

update records in a union select query

I’ve two tables with events that I want to union and sort by date and I need a value in the result that I can group the records by for reporting – in this case code2 CREATE TABLE #tbl1 (code1 INT, codeDate DATETIME, code2 INT) CREATE TABLE #tbl2 (code1 INT, codeDate DATETIME, code2 INT ) […]

Entity framework move/archive data from one database to another

I have the following scenario: I have a production database which is highly transactional. In order to keep queries efficient I would like to archive data from some of the tables to another database with exactly the same schema. The relationships between tables are not very complex but any dependent objects would have to go […]

The multi-part identifier “System.Data.DataRowView” could not be bound.”

I am making a small database using sql server as the back and vb as the front end, I have nearly made it work however I have stumbled across this error: An unhandled exception of type ‘System.Data.SqlClient.SqlException’ occurred in System.Data.dll Additional information: The multi-part identifier “System.Data.DataRowView” could not be bound. Here is my code: Imports […]

NPM Install Error – Msnodesql

I’m running npm to install msnodesql, an npm library for sql server drivers. I am installing this on a Windows Server 2012 box. I have installed Visual C++ 2010, node-gyp and Python 2.7.x.x as dependencies, and all of these installs were successful. When I run npm install msnodesql, I get a big red error: (x86)\MSBuild\Microsoft.Cpp\v4.0\Miscrosoft.Cpp.InvalidPlatform.Targets(23,7): […]

Entity Framework listening to SQL Server changes

I’m working on the following scenario: I have a console up that populates a SQL Server database with some data. I have one more web app that reads the same database and displays the data on a front-end. Both of the applications use Entity Framework to communicate with the database (they have the same connection […]

To store value as xml format in a column in SQL Server

I have a table called User with a column Orders.. Orders will contain orderID of the user.. Single user can have multiple OrderID‘s so I need to store multiple values in one column using xml.. Need to store like this in a column <Orders> <OrderID>45586</OrderID> <OrderID>45578</OrderID> </Orders> How to do that using a stored procedure […]

Abort running of stored procedure when another instance is running

I have a stored procedure which is supposed to execute at a regular interval to do some heavy background processing on the backend. The amount of data the stored procedure has to deal with is variable. I intend to set up the stored procedure as a scheduled job. Because the processing must be done sequentially, […]

“The target database schema provider could not be determined” With VSDBCMD but Only When /ConnectionString is Specified

I have been developing a deployment script to deploy our database project to multiple database instances. I’m testing it by running it manually. It is a very simple script, and just runs VSDBCMD against a deployment manifest created to deploy our base, or template database. In order to deploy to different databases on the same […]

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