How to parse XML attribute using MS SQL

I need to get the values of attributes present in XML document using MS SQL query Ex : I have a XML which looks below <trade xmlns=”www.somewebsite.com” Action = “Insert” TradeNumber = “1053” Volume = “25” DateTime = “2013-12-06T10:22:47.497” PNC = “false”> <Specifier Specifierid = “112” Span = “Single” Name = “Indian”/> </trade> I need […]

Stored Procedure sometimes timeouts when calling via RPC, but always OK when calling in SQL

We have a very strange problem: We have a stored procedure which returns a set of data. This procedure does a rather complex join and aggregation, so it takes 700 Milliseconds to execute. When called directly in SQL Studio, the procedure ALWAYS returns correcty and always takes about 700 ms of time. However, when called […]

Postgresql. Create table with column that concatenate values from other columns

I have create table script in MSSQL: CREATE TABLE [dbo].[Address]( [Id] [int] IDENTITY(1,1) NOT NULL, [Street] [nvarchar](100) NOT NULL, [BuildingNumber] [nvarchar](15) NULL, [ApartmentNumber] [nvarchar](15) NULL, [City] [nvarchar](100) NOT NULL, [Country] [nvarchar](250) NULL, [Postcode] [nvarchar](15) NULL, **[Search] AS (((((((([Street]+’ ‘)+[BuildingNumber])+’ ‘)+isnull([ApartmentNumber],”))+’ ‘)+[Postcode])+’ ‘)+[City]) PERSISTED,** CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, […]

SQL Server – Selecting multiple maximum values matching two separate corresponding cells

I am a beginner in SQL and been trying to obtain all of the maximum values as per the access strength and folder names, with allowing groups to the folders being displayed accordingly. I tried using MAX function but it was returning only 1 maximum result. Thank you in advance for any help or guidance […]

Select only rows where time difference is x hours

I have a table passenger_log with four columns psngr_id (not necessarily unique), arrival_dt_tm, departure_dt_tm and timediff (the difference between the passengers last departure date and next arrival date). From this table I’d like to be able to select only rows where the time difference is less than 24 hours and also select the next row. […]

How to query to get only rows where a change took place? (changes can go back and forth)

I’m working with a table that has dozens of rows per customer, each with a date and several columns representing various statuses. I’m only interested in pulling the rows where a change took place in one particular column (specifically 0 to 1 or 1 to 0, see status column below). I can’t simply use row_number() […]

sql server equivalent of Oracle High Water Mark

Does anyone know a way I can find how many records a table has previously held / how many pages it has had / some other way to identify its previous max size? The result does not have to be totally accurate but rather indicate the scale. We have a table that fulls and empties […]

Finding Number of Bits set in a VarBinary, SQL Server 2012

(Note:- There may be syntax errors in the code i write here) I have a Table with 2 Fields CREATE TABLE Traces ( TraceName VARCHAR(100), BlockVector VARCHAR(MAX), NumHits INT); There are around 1 Millions Entries in the Table. I want to achieve following things from that table: 1) For each row take a bitwise XOR […]

Insert last X Week Numbers into Temporary table

My Question I am trying to write a stored procedure that retrieves the week numbers for the past X weeks and then inserts them into a temporary table. So far I have been able to create the temporary table and return the contents (not very hard). However, my issue now lies with the inserting of […]

get the last modifed user for a sql job agent job

The schedule for one of my job agents jobs has recently been disabled, is there anyway to find out any information other than last modified date on who or what disabled the job schedule?

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