Skip to content
Advertisement

Tag: tsql

How to pull the latest records added in a table?

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

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

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

Advertisement