I have table that is storing historical values for data in other table: Now I need to generate from such table “change log” which will show what was old value, new value and when update occur: Unfortunately, I can’t change structure of the existing table and can’t put old value there, …
Tag: sql-server
Laravel binding parameter using insert() with convert() inside
I am having a hard time binding my SQL query and I only have a few braincells left. Basically, this code works but prone to SQL injection: return DB::connection(‘sqlsrv_rfo_user’) ->table(‘dbo….
Query to replace ID with Name within the same table?
Can anyone help me figure out this SQL Query? I have the following table: I want the new table to look like this: So essentially I want to replace the third column from “ManagerId” to “Manager Name,” where all information is retrieved in the same table. Can anyone help me with the quer…
I have to get the total time spent for a question using SQL. I am unable to get the total time and provide the answer in minutes or H:M:S format
I am trying to find the total time taken per person and provide the answer in total minutes spent using SQL. The page_start_time is time data type.The data is shown below: This is the visitors table. I need to find the total time taken using the page_start_time field per USER_ID. I tried the following code: I…
Sql Grouping insight Xml
I need to get different row data to 1 row based with id and need to group by its status. I tried in several ways and finally found a solution using xml, but when I use xml I don’t get the output I want. This is a sample code I used to try the logic. returned output: expected output: Answer
Update duplicate data with same unique-identifier
I have the following table in my database: So I want to generate Unique-identifier and Update the UniqueID column as shown below: If values of UniqueID are the same, then they must have the same Uniqueidentifier. I have tried to write a CTE as below: But am not getting what am looking for. Very knew to the wo…
Linear extrapolate values down to 0 from variable starting points
I want to build a query which allows me to flexible linear extrapolate a number down to Age 0 starting from the last known value. The table (see below) has two columns, column Age and Volume. My last known volume is 321.60 at age 11, how can I linear extrapolate the 321.60 down to age 0 in annual steps? Also,
Can I use a derived column in SQL Server for performing a CASE function?
I have a ‘main’ table, C1, which has a record identifier, which in turn may be linked to either an account or a customer ID. The relationship / linkage is stored on two separate tables, one with record ID – Account level relationship, and the other with record ID – Customer level relat…
How to PIVOT a select result as mentioned in the query
I have query as mentioned below which will return a table like I’m trying to PIVOT this result as below Answer You can try the below way –
Trigger for UPDATE runs many time on batch Updates
All of my tables have a Trigger for CRUD operations. here is a sample: If I update one row, everything works fine and trigger inserts one row in history. For example But if more than one row updated, updatedrow^2 rows will be inserted. For example 9 for 3 rows 100 for 10 rows… What is wrong with my trig…