I have a table, that keeps track of store holiday hours: This is a highly oversimplified table. There’s about 30 columns horzontially consisting of store operating hours by date – It continues (DATE3, TIMES3, DATE4, TIMES4, etc). I need to unpivot the values vertically, ensuring the date and time …
Tag: sql-server
Determining cause of query timing out
I have a query that I’ve spent some time optimizing, it will normally run in less than a second. Occasionally, though, it will take a minute or two to run which causes the calling application to throw …
SQL Subquery to handle duplicates
So I am joining to tables, however the table I want to left join has duplicate values for the matching field. I am trying to create a subquery so that when there are duplicates the column value is assigned ‘Duplicate’ and when there isn’t then it takes the value of the join. Here is simplifi…
Rolling Multiple Rows into a Single Row Based on Matching Data in SQL Server
I have a table in SQL Server with the following layout and some sample data: Is it possible to consolidate like ReferenceNumber rows into a single row, so: I’ve tried: which outputs: Any help would be greatly appreciated. Thanks Answer Assuming this is for small (ish) amount of data, you can correlate t…
Are SQL Server sequences guaranteed to always generate unique values even if called simultaneously from multiple connections?
This is a follow-up question to: Are SQL Server sequences thread safe? I have two separate stored procedures that are calling the same sequence. The stored procedures are launched “in parallel” from an SSIS package. There is no synchronization of any kind between the two stored procedures (other t…
Check whether a number is in a string range
I have a table ID Count Range 1 33 1-100 2 120 101-200 3 155 201-300 The Range is a string that can only have the values 1-100, 101-200, 201-300. I need to write a query that checks whether the count and the range fits, so 155 should pop up. My idea was: but this does not work. Can anyone
Combine two tables with different columns and data
How can I combine two tables with different data and set value for CompanyC to all data in Table 2 even there is no relationship of CompanyC on Table2. And the Result Table would be like: I already tried this and it is working but the problem is since CompanyC has no data on Table 2. The result will be
Copy a dependent table
I have this customers table (I’m using SQL Server): About 300 customers were registered in this table. I created another table in another database and inserted these customers into the new database. Here is the new customers table: But I have an operation table as well and I didn’t change this one…
Convert SQL result from Hash to Varchar
I have some data in an SQL table that is hashed, and am trying to convert these variables back to a string, however everything I get back is gibberish. I have tried all suggestions on Stack Overflow, …
How to have different values of a single column in a condition where in sql?
I write a SQL query to get different sales information about stores. The problem is that I would like to filter and take only some store numbers in my “GL_ETABLISSEMENT” column, if I just do …