I want to pull the records associated with the latest VERSION_ID. FILE_EXTRACT_VERSION table looks like this: FILE_EXTRACT_VERSION_SPECS table looks like this: I want to write a query to pull records with the latest VERSION_ID (latest can be segregated by the latest date they have been added) Here is what I have tried but it gives an error: Only one expression
Tag: tsql
Seed Data using merge statement including data from external table
I’ve been provided an excel file with data that I am supposed to merge into a database. From this data I am concatinating a string in this format: ‘Maastricht’ here is the name of a city, which I need up in a foreign table during the insert. This is the script that I have come up with: To Replace the
Query to Id referencing to an ‘Id’ to the same table
I have a table AMZ_EMPLOYEE_DETAILS with Employee Id, Employee Name and Supervisor1 and Supervisor 2. The Supervisors are employee itself but represented by their name. My task was to replace the Supervisor names with their Ids. I have used the following query to obtain the solution but it uses sub-queries and the query does look optimized. For this I have
Update table data, fetched from another table
I have a table which is storing the attendance information on an employee and another table that’s storing the information about the shift of the employee which is basically a duty roster. Here is …
Tuning a query converting subquery
I was trying to change an update statement where there is a subquery in the WHERE clause to a join in order to improve performance. DDL to sample table/data CREATE TABLE [dbo].[Table1]( [pre_plan_id]…
Provide the values for a ‘like’ function from a specific column in a Table?
I am using SQL Server 2014 and I need a T-SQL query which uses the like function to run on a specific column (c1) of a Table (t1) to find out if it contains one of the codes from a list of codes found …
How to SUM columns in the same row?
I have a table like below: id pymt_no1 pymt_no2 pymt_no3 pymt_no4 pymt_amt1 pymt_amt2 pymt_amt3 pymt_amt4 25 100 5 150 50 …
Reverse order of every other character in a string
I’m currently working on a project where the data I’m receiving is being given to me in a messed up order. I need every 2 characters to switch places in a string. Currently I have the below code, but it is ungodly slow in a function or stored procedure. Any help would be appreciated. Ex: FK741 OCEV needs to be
How to group records by hours considering start date and end date
I’m trying to group records by hours with consideration of duration. Assume there are long running processes and there is log data when process has been started and finished. I’m trying to get report by hours how many processes were running The data looks like this Process_name Start End ‘A’ ‘2019/01/01 14:10’ ‘2019/01/01/ 14:55’ ‘B’ ‘2019/01/01 14:20’ ‘2019/01/01/ 16:30’ ‘C’
SQL Exist in either TableA or TableB
I am attempting to create a script which needs a clause to check of a column value in Table 3 exists in Table 1 or Table 2 Msg 4145, Level 15, State 1, Line 44 An expression of non-boolean type specified in a context where a condition is expected, near ‘)’. Answer Problems with your query: Missing parentheses on the