Skip to content

Tag: sql-server

UNPIVOT Holiday Hours

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 …

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…

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…