I have used SqlDataSource and have a select query based on District & Zone as below It’s an inline query. I have tried above query but not able to figure out how to Select condition based. I want if district supplied then Select according to District, if both District & Zone supplied then Select according to both & If nothing
Tag: sql-server-2012
How do I create a table from distinct values in another table?
I have a table of orders that I want to create a table of possible customers from. I would like to take the distinct names in the customer record and create new table in the same SQL database with and assign it an auto incrementing Id as the PK. How can I script this? Answer
SQL Server LEAD function
I am getting the following error when I run this query. [42S22] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name ‘NEXT_DATE’. (207) (SQLExecDirectW) This is a leetcode medium question 550. Game Play Analysis IV. I wanted to know why it can’t identify the column NEXT_DATE here and what am I missing? Thanks! Answer The problem is in this CTE:
Aggregate time from 15-minute interval to single hour in SQL
I have below table structure in SQL Server: Is there a way to group above data into one hour interval instead of 15 minute interval? It has to be based on start and end columns. Thanks, Answer Maybe something like the following using datepart?
Flag items not having the specified combination in a column
I need to flag ID#s not having a specified combinations of DC and Storage Locations. For example: Articles must have the following combinations for each DC: DC Storage Location DC01 ABC, BCA, DCA DC02 ABC, BCA DC03 ABC, DCA My desired outcome would be the below as I’d like to show the Storage Location missing. ID# DC# Storage Location Flag
Update column by removing text in braces
I need to update single column for all the rows in a table. The update should happen in such way that data needs be filtered out by removing all text where braces are appended for the string and swap the strings separated by ‘,’. Example: As per the above example, I need the final data to be something like this
How to Convert Hours, minutes and seconds (HH:mm:ss) to minutes and seconds (mm:ss) in SQL
Suppose I have 2hrs, 47minutes and 10 second (02:47:10) which is in hh:mm:ss format as a value in Time column. I would like to convert it to minutes and seconds only (mm:ss). Hence the result should be 167minutes and 10 secs in sql. I have tried using the code The result was 167.166666. My desired output should be 167:10 (mm:ss)
SQL Server : fastest way to change rows to columns
I’ve got an issue regarding two tables in my database that have the following columns: COMMENT table Composite key made up of (KEY, TYPE, NUMBER) RESULTS table An example of the COMMENT table would be this: For each KEY, there are only 3 different types A,B,C and one TYPE may have up to 0020 in the NUMBER field. These records
CASE Statement in WHERE Clause SQL Server
I’m having trouble sorting this out. I want to see the fiscal quarters for Date_Received. When the @ReviewPeriodQuarter = 1 then I want the Date_Received months 10,11,12. If @ReviewPeriodQuarter = 2 then I want the Date_Received months 1,2,3 etc. SQL Server doesn’t like the BETWEEN part of this. Thanks Answer You can either do it with more parameters like Larnu
Transform properties from JSON array into comma-separated string
I have a string column in an SQL-Server table on Azure which contains the following data: How can it be transformed into a comma-separated string containing “Jane, John”? Answer Here how to achieve this via a snippet of some of my older code, you should be able to loop through the table and do this for each row. There may