Tag: sql-server-2012

IN operator not finding matches

I am not able to select values with IN clause using single quotes. The pid column is varchar(50). select * from t_tra_main where pid in (200000002,300000394,200000004, 200000001,300000378,300000393,300000379,200000003) select * from t_tra_main where pid in (‘200000002′,’300000394′,’200000004’, ‘200000001’,’300000378′,’300000393′,’300000379′,’200000003′) The first query returns data, but the second query does not.

SQL Server 2012 on Amazon RDS cannot attach mdf with Management Studio

I have set up a Sql Server 2012 on my amazon rds. I have verified i am running the 2012 server and i am able to connect with my username and password that i have created during the wizard creation process from amazon aws. I am trying to attach a mdf and when i right […]

SQL Server- not permit empty string and have null instead (similar to Oracle)

In SQL Server 2012, is there a way to have the database act similar to Oracle in the way that an empty string = NULL? I don’t want to permit empty strings in my database and want these to purely be NULLS. Thanks

SQL Server : returning the related xml with value, nodes methods

I have a the below sample XML schema that I am querying from in SQL Server 2012. I have a table with a XML column. I want to include the snippet of xml when each row is returned. Below is the existing query and more detailed explanation. <dev:Doc xmlns:dev=”http://www.w3.org/2001/XMLSchema” Number=”0″ SchemaVersion=”0.1″ Settings=”Testing” Title=”Ordering”> <dev:Forms FormId=”A1″> […]

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 ) […]

Sql Server Value Method Returning only one value not multiple

I am trying to return multiple element values into rows and I am running into the below issue of it not returning all instances in rows, I have isolated the issue down to a singleton problem. I have referenced the below links: http://www.jasonstrate.com/2010/11/xquery-for-the-non-expert-value/ http://msdn.microsoft.com/en-us/library/ms175894.aspx I have tried these: ,c.value(‘(Tags/Tag/text())[1]’ , ‘NVARCHAR(20)’) AS Tag And ,c.value(‘(//Tags/Tag)[1]’ […]

create a file system group pointing at a SAN

I am working with creating a FileTable in sql server 2012. I want to store the files on a SAN (Storage Area Network). I have mapped it to a drive on sql server. To use the FileTable, I need to set up a file system group. I am using the following script but failing to […]

Selective Xml Index causing Insert Error: string or binary data would be truncated. the statement has been terminated

I was receiving the error: string or binary data would be truncated. the statement has been terminated. Inserting XElement data into a SQL Server 2012 Xml column from C# via Linq-to-SQL was causing the error. After running Profiler and other tools, I was able to find that one of the attributes in the XML was […]

Calculating a running count & running total across customers with SQL

I have the following table (SQL Server 2012): DID – cust id GID – order id AMT – order amt Gf_Date – order date SC – order reversal amount I’m trying to calculate a running count of orders and a running total of sales by customer so that I can assign a flag to the […]

Querying the resultset of a stored proc

This question already has an answer here: Insert results of a stored procedure into a temporary table 24 answers SQL Server – SELECT FROM stored procedure 15 answers

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