Fails when an lock of an object exists in SQL Server

I followed the example given here of sys.dm_tran_locks, but instead of the second session blocks until the rollback of the first session, I need it to fail automatically if the lock exists, perhaps wait for a little amount of time before it fails. Is there any parameter that I could configure to get that behavior? […]

Executing Queries Stored in a Column of a Table

I need some help about executing queries stored in a column of a table. My table name is Stats. It includes some reporting queries like this: id | key | query —— | —— | —— 1 | reportA | select 1 2 | reportB | select 2 3 | reportC | select count(id) from […]

Select values from one table based on specific value of another table Linq

I have 2 tables: Location id | user_id | latitude | longitude| 1 | 2 | 11.32323 | 11.32323 | 2 | 3 | 12.32323 | 12.32323 | 3 | 4 | 21.32323 | 12.32323 | Task id | user_id | status | 1 | 2 | 0 | 2 | 2 | 1 | […]

Return Vales when

I’m stuck here, guys. I have two tables, each having a date column. One table is using timestamp (2016-08-05 09:16:11.000) the other has timestamp but isn’t using it (2016-08-05 00:00:00.000) I want to join these tables and return the MAX date from each table but ONLY when the MAX dates match. If one column has […]

How to use SQL variable to iterate XML nodes

I have this XML in SQL Server 2008: DECLARE @xml xml = ‘<Root> <Contacts> <Contact name=”John Doe” type=”REG” other=”value” /> <Contact name=”Jane Doe” type=”REG” other=”value” /> <Contact name=”Jennifer Doe” type=”REG” other=”value” /> <Contact name=”Jane Doe” type=”REG” other=”value” /> </Contacts> </Root>’ I want to change the value of the types to something else. I can hard […]


SELECT h.* FROM h LEFT JOIN au ON au.ID = h.Key AND au.RaID = 40190 AND h.EntityType = ‘Detail’ LEFT JOIN ip ON ip.ID = h.Key AND ip.RaID = 40190 AND h.EntityType = ‘itempart’ WHERE coalesce(, is not null Anyone have a good idea how to optimize this? h is HUGE history log table.

Laravel 5.3, CentOS, PHP 7 – How to connect MSSQL?

I have a project (laravel5.3, php7, centos7) pulling some data from MSSQL (not my choice btw). So, on XAMPP I was able to get it running successfully with ease using pdo_sqlsrv, however thats only for windows. So how do I get it running on CentOS? Thanks.

Given a Week Number, Return the First Day of the Week in T-SQL

This will give me a week number based on a date: SELECT DATEPART(wk, ‘7/27/2016’) AS [Week] For example, that returns 31. Now, what I need to do is find the first day of that week, and return it in a short date format. For example: Given Week: 31 Return First Day of Week: July 24 […]

Passing irregular xml file to the stored procedure

I have a sample xml as follows. I am trying to get all or specific data and then insert into the my sql table which has the same columns representing the values coming from xml. I looked through some solutions but the xml files are not formatted like I have in here. Can you help […]

Map foreign key to scalar property

I have 2 tables: Data and AdditionalData. Their relation is 1 to 1-0 (any Data can have 0 or 1 AdditionalData). For main context I have classes: class Data { public long Id {get;set;} // PK public string Name {get;set;} public AdditionalData AdditionalData {get;set;} // can be null } class AdditionalData { public long Id […]

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