Skip to content
Advertisement

Tag: tsql

using DateDiff to find duration in minutes

I am trying to use Datediff to find out the duration between columnA and columnB. This produces errors. Can anyone please help me with what I’m doing wrong? Answer how about trying this, not sure why you have stime = [exceptions2].starttime and etime = [exceptions2].endtime

Should every SQL Server foreign key have a matching index? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago. The community reviewed whether to reopen this question 7 months ago and left it closed: Original close reason(s) were not resolved Improve this question

Only inserting a row if it’s not already there

I had always used something similar to the following to achieve it: …but once under load, a primary key violation occurred. This is the only statement which inserts into this table at all. So does this mean that the above statement is not atomic? The problem is that this is almost impossible to recreate at will. Perhaps I could change

Delete duplicate records in SQL Server?

Consider a column named EmployeeName table Employee. The goal is to delete repeated records, based on the EmployeeName field. Using one query, I want to delete the records which are repeated. How can this be done with TSQL in SQL Server? Answer You can do this with window functions. It will order the dupes by empId, and delete all but

Case expressions may only be nested to level 10

I have the following code for handling phone numbers such as country code for Australia +61, 61, 001161 etc. The problem that I have I can’t insert any CASE statement anymore under: CASE WHEN LEFT(@BPartyNo, 4) = ‘+610’ It said that Case expressions may only be nested to level 10 How do I streamline this TSQL so I can put

Is there a combination of “LIKE” and “IN” in SQL?

In SQL I (sadly) often have to use “LIKE” conditions due to databases that violate nearly every rule of normalization. I can’t change that right now. But that’s irrelevant to the question. Further, I often use conditions like WHERE something in (1,1,2,3,5,8,13,21) for better readability and flexibility of my SQL statements. Is there any possible way to combine these two

Remove trailing zeros from decimal in SQL Server

I have a column DECIMAL(9,6) i.e. it supports values like 999,123456. But when I insert data like 123,4567 it becomes 123,456700 How to remove those zeros? Answer A decimal(9,6) stores 6 digits on the right side of the comma. Whether to display trailing zeroes or not is a formatting decision, usually implemented on the client side. But since SSMS formats

Advertisement