Tag: sql-server-2012

Move Columns to next if null

I want to move color forward to next column if the required columns are null however I used COALESCE function but I am unable to get expected result Below is my table structure ID. Level1. Level2. Level3 Level5 1. Xyz. Null. Null. Null 2. Abc. Xyz. Null. Null 3. Mno. Abc. Xyz. Null 4. Ggg. […]

bcp throwing unexpected EOF error unless the file has an extra \n

I’m importing a tab delimited text file to SQL Server 2012 via BCP. It’s working except for the final line of the file, which is not imported. This is not the usual unexpected EOF issue where the delimiters are set incorrectly or a comma exists in data using a comma delimiter. The field delimiter is […]

Result Value on the same row

I want all the value with the same ID to be on the same line in the query below. I do not know how to go about it. Please help DECLARE @Tab TABLE (ID INT, Day1 Varchar(10), Day2 Varchar(10), Day3 Varchar(10), Day4 Varchar(10), Day5 Varchar(10), Day6 Varchar(10), Day7 Varchar(10), Day8 Varchar(10), Day9 Varchar(10), Day10 Varchar(10) […]

Text message via SQL Server

We have some to critical jobs in our production system. We receiving email about of job status succeded or failed and also we want to set send text message from SQL Server. I searched but looks not so possible, has anybody tried before ?

IF EXISTS then Update else do Nothing – SQL SERVER 2012

I have a table which assigns roles to particular users. I am doing mass update to this table where in I am end dating some users previous roles and after that is completed assigning them new roles by inserting into this table. I am doing both these actions separately. For my first action my code […]

T-SQL progressive numbering partitions

I am aiming to obtain a record set like this date flag number 01 0 1 02 0 1 03 1 2 04 1 2 05 1 2 06 0 3 07 1 4 08 1 4 I start from the record set with “date” and “flag” only. I am trying to compute the “number” […]

Database Consolidation – Named instance vs default instance

I have searched SO, but cannot find a question/answer close enough. We are busy consolidating our database servers, partially due to address performance issues using cross-server (cross-instance – SEE: RPC) queries. A lot of extra thought is put to trying to manage the “chunk of data over the linked server” vs just letting the compiler […]

SQL Server 2012 : alternative to XML PATH

I have been tasked with reworking a set of existing legacy queries. The main problem I can find is they all use XML PATH() to make updates to various temp tables before returning the results. It breaks down like so, we create a temp table with the basic information as distinct values. OwnerId | FName […]

SQL Group by Client Location

Sample of Data I am trying to manipulate Order | OrderDate | ClientName| ClientAddress | City | State| Zip | ——-|———–|———–|—————|——–|——|——-| CO101 | 1/5/2015 | Client ABC| 101 Park Drive| Boston | MA | 02134 | C0102 | 2/6/2015 | Client ABC| 101 Park Drive| Boston | MA | 02134 | C0103 | 1/7/2015 | […]

Using Import wizard to import Excel data into table in SQL Server 2012 failing – text truncation

I have an Excel file that I import weekly into a table. I am using Excel 2010 and SSMS 2012. The import failed this week and I have been unable to determine why. I was able to successfully import the data into a new table. The table definitions of the new table match the ones […]

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