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 …
Tag: tsql
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
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 query previous 8 quarters for quarterly data report using sql server?
I want to query the previous 8 quarters from today’s date. Example: last quarter from today’s date = ‘2020-09-30’ and last 8 quarter from today’s date is ‘2018-10-01’. I want the last 8 quarter previous (‘2018-10-01’) mark as Q1 in my query result instead of Q4 since it’s the 4th quarter of the year 2018. Q2 would be the next
Get the Defect Type with the maximum Total Defect Qty
I have the following query which gets the sum of defect quantity per Defect Type : SELECT [Defect Type] ,YEAR([Date]) AS YearOfDefect ,SUM([Total Defect Qty]) AS [Sum] FROM SupplierQuality GROUP BY […
How can I create summaries across columns?
I have an existing application database table supporting an application, and I’ve been tasked with adding another feature. Currently, we have a build table that stores information about product builds….
Procedure with cursor has missing output
I am working on an SQL Server procedure that I would like to have print the department name and students name Similar to the attached snippet The formatting should look like the attached sample snippet and there are two columns involved. students and department tables. The problem is that the results are incomplete/seems to be getting cut off below is
How to do not null check on LEFT function on the select query
I have a query that returns some demographics like firstName, lastName, MiddleName and i need to use LEFT function on each to filter the First Letter of each column like LEFt(firstName, 1).This is …
SELECT statement with where clause on Column
I am trying to gather some data from a table with INNER JOIN with another table. What I am trying to get have 2 Types and I need to separate these 2 types in 2 different columns. In table where I am Inner joining have a column called ‘Data’ and another Column called ‘Type’ depending on the type of data