I understand my mistake with creating questions in StackOverflow, so I want to rewrite my question. I have two tables. One of them is my target table with old data and the source table with new data. Implicitly I want to compare these 2 tables and get information on which columns have been changed and changed status. So I created
Tag: sql-server
Find numeric record number in string
I’ve been using this site for longer than I can remember, but I’ve never had to ask a question before – I’ve always been able to find what I need – but this one could use some SQL expertise for the best approach since it’s kind of a worst case. I have a text comment field that gets a lot
How do I create a trigger that will update a column if inserted or updated row is not null?
Table is EmployeeTest Column EmployeeCode has a Unique Index where it can allow NULL but cannot be duplicate. It is varchar (16) I want to update the EffectiveDate column I want to create a trigger for whenever I insert or update a row in the table, if EmployeeCode is NULL, then do not update EffectiveDate. If a row is created
Parse utm parameters in sql query
I have a table in my database that tracks visitors page views and I am trying to pull out the utm tracking parameters from the url You can use this script to create table This my script I am getting funny results where if there is no utm tracking it is still populating fields and the utm_id is incorrect in
SQL: date type column with only mm-dd
I want to create a column of data type having only ‘mm-dd’ values. Is it possible and if yes how should I do it? Note: Instead of “2022-06-07”, I want “07-06” Answer There is no date type that can store that format – in fact none of the date types store a date and/or time in any of the formats
How to optimize my query speed (avoid using subselect for every row)?
I have a table called CisLinkLoadedData. Is has Distributor, Network, Product, DocumentDate, Weight, AmountCP and Quantity columns. It used to store some product daily sales. AmountCP / Quantity is the price for the product at certain date. There are promo and regular sales, but no flag for it. We can tell if certain record is regular or promo by comparing
Query to pull the data from 3 tables based on latest load date and HashKey
I am trying write a SQL query to pull the data from 3 tables using JOINS on basis of common HashKey and I want to take all the updated records from 3rd table based on the load date(last increment/recent records) using SQL. I have tried below SQL query but I am not able to get the recent record from third
SQL: Two similar queries into one query such that returns one table with two columns
I want to run two queries that are pretty similar such that the query returns one table with two columns (one column for each query ran) Query #1: Query #2: Desired return: admin administrator groupID.1 groupID.1 groupID.3 groupID.2 Is it possible? I was able to get the expected return by doing a FULL OUTER JOIN but I read that JOINS
cast numbers and decimals into INT
I have [funds] that have been presented in different formats, some are decimals, others numbers: etc I tried to use this: ,CAST (REPLACE ([funds],’.’,”) AS INT) AS [funds] but got this mistake: The conversion of the varchar value ‘288294130100’ overflowed an int column. How do I ned to treat the combo of numbers and decimals? Answer You can cast them
Re-aligning dataset so that different period appear on the same row
I have each entity data over three different [periods]. These are: 2022-03-31, 2021-09-30 and 2021-03-31 I want to alter the dataset and have This can as such easily done by case statements. The problem is, I want that data to be aligned, so that [entity] appears and then on the same line [curr_period], [prev_period], [prev2_period] How can this be achieved?