My sample data is as follows: Table T1: +——+——-+ | Item | Order | +——+——-+ | A | 30 | | B | 3 | | C | 15 | | A | 10 | | B | 2 | | C | 15 | +—–…
Tag: sql-server
How to add a column in MSSQL with default value?
In MSSQL 2014 I would like to use an update syntax which is adding a new column with a default value. Is this possible somehow? Answer Here is a complete reproducible example. Create table Check contents Add new column with default value Check the result Here is a SQL fiddle with this example.
Apply if only on one column on result
This are sample template UserDetails : id,UserName,IsShow Brand : id,BrandName Product : id,ProductName BrandProduct:id,brandid,productid,price If Isshow is false, show entire price else …
Send mail every N days in SQL
I need to send a warning mail 14 days before certificates valid_to date ends and also send email every 3 days from delay_days. Table Certificates consists of: ID(int) | cert_valid_to(date) | …
Based on the value in one column change the value in another column across group
I am new to SQL Server. I have a table: Group id DEPT marks ————————————– A 001 CS P A 002 ECE P A …
How to store T-SQL query output in new table with date of that day when query executed
I have to created a query which i have to run daily and attach the output in Excel. But what I want is to schedule the query to run on a daily basis and the output will get stored but I’m not able …
Select every 2nd, 4th row and so on from same column based on specific material
In 1 packing got 2 material and item sequence is 00010 and 00020. What I need is if I input material from item sequence 00010 in where statement which is ‘CB016’ , I can list out all the item sequence …
Split single row into multiple rows based on Date and time in SQL Server
I want to split a single row into multiple rows based on time. below are the example. Expected output is below: Day start from 06:00 AM to next day 06:00 AM. When EndDate time is grated than 06:00 AM then split this date in two rows. first row end date is 2018-08-21 05:59:00.000 and next row start 2018-08-21 …
SQL BCP Unable to insert value for identity column
I am using bcp utility to import a tab delimited file. My table has an identity column, when I run bcp command I get error as Error = [Microsoft][SQL Server Native Client 11.0] Invalid date format Second column is datetime. When i use -E flag (as suggested by many), I get error as Error = [Microsoft][SQL Serv…
I have a result set of continuous days and a severity rating. I would like to aggregate these into StartDate, EndDate, Severity
In SQL Server I have a table with the following data Date Severity 2018-09-10 40 2018-09-11 40 2018-09-12 40 2018-09-13 40 2018-09-14 40 2018-09-15 40 2018-09-16 20 2018-09-17 20 2018-…