Is there a way to update a table using a JSON field in SQL. { “RelationshipType” : [ { “ID” : 1, “FromID” : 70, “ToID” : 12 }, { …
Tag: tsql
Where clause only return one condition instead two using OR
I have a simple select statement like: SELECT * FROM [customer] AS [c] INNER JOIN [customertype] AS [ct] ON [c].[CustTypeKey] = [ct].[CustTypeKey] INNER JOIN [ProjectCustomer] AS [pc] ON [c].[…
How to Pick Column names from table
I have tables which have columns and tables Name EmpId Empname DeptID DeptName Employee Department I have INFORMATION_SCHEMA.COLUMNS to get Table names Script : I have got table names Select …
SQL – trigger select into after update/insert
i have a table called Audit_Data, and from time to time there is an update coming. Every single update consists of around 300 rows (around 20 columns per row), and all of the rows from the same update …
Combine queries to show one set of results
I have two separate queries where I need to match up and combine together based on a date value. select convert(varchar,Delivery_Date,101) as ‘Date’, sum(case when billing_group = ‘3’ and …
How to use a table variable within EXECUTE command?
I have this code: DECLARE @mytable TABLE (x INT); EXECUTE (‘SELECT * FROM ‘ + @mytable); When I run the code, I get this error: Must declare the scalar variable “@mytable “. I know that @mytable …
Cannot exclude previous non-duplicate rows
In a nutshell, here it is: I have 1000(ish) employees who have multiple recurrent annual training requirements I need to be able to sort the employees by County, Facility, Employee, and Type of Training (and also allow for sorted lists at each level) I want to display only the most recent date the Employee took the training What I’ve tried
How subquery works?
My understanding of the logical order of execution of sql query is that FROM which gives us the base set of data WHERE which filters the base set data SELECT returning the filtered data I am not able to wrap my head around in the working of this query which contains a subquery:- I mean here, when WHERE is filtering
How is this code adding a number to a datetime without using DATEADD? [closed]
In the following SQL statement there’s some T-SQL that adds a number to a datetime and to a date: declare @t table(UserID int, StartDate datetime, EndDate date) insert @t select 1, ‘20110101’, ‘…
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) | …