Skip to content

Tag: tsql

Capturing difference between 2 tables in one table

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…

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 …

Incorrect syntax near ‘<' in SQL Server Scalar Functions

Here is the requirement: Find all teachers whose FirstName length is less than 5 and the first 3 characters of their FirstName and LastName are the same I tried this query (Scalar Function): To call function: But, when I execute first query, it shows error: Incorrect syntax near ‘<‘. Can anyone…

Return only the modified records in a table, using T-SQL

I’m attempting to return only the modified records in a table, using T-SQL. This is what I’ve done thus far: Results: Expected results: The following statement returns all the 0 to 1, and 1 to 0 records and I don’t understand why: Answer To track the changes at whole dataset, you were almost…

Conversion Failed in a CASE expression

I have a column that is of varchar type, it contains dates and ‘#’: I am trying to convert the dates to the standard date format (YYYY-MM-DD) and leave the ‘#’ as it is whenever it occurs. Here is my code: The outcome column is also of varchar(10) type (same as the original column). I …

Assistance with PERCENTILE_CONT function and GROUP By error

All, I am having problems with the below query. I am trying to get stat data from our database for the last 3 years but I keep getting the error message: ***Column ‘OC_VDATA.DATA1’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.*** …

Return distinct results that appear more than once

I have the following data: Result should be: Note that the result find unique combinations of ID and Site that repeat more than once for a given ID. I did the following query but does not return the result: Answer See: DBFIDDLE The SELECT ID, site FROM table1 GROUP BY ID, site will select the distinct values.…

Search in the database

This Messages form display table with these informations (ID,FROM,TO,TITLE,MESSAGE). I am trying to search for all the messages send to a certain user . user will enter his name in the Search_textBox then it will filter the table to keep only messages to this user. I get this error : Answer this is Correct