A file supplied by a Client has the following structure: FullName Mr John Joe Smith They would like this transformed to the following: Salutation FirstName MiddleName LastName Mr John Joe Smith I’ve looked into this and I’ve tried the following: This produces: Salutation FirstName Mr John Joe Smit…
Tag: tsql
Running count SQL server
Can someone please help me in counting the rows in SQL Server Expected result Answer Try this:
Dynamic SQL mistakenly looks for table variable
my code accepts table name parameters and my dynamic code is supposed to query a table. I consistently get the error: @sourcetbl variable must be declared. After a lot of troubleshooting, I realized …
Dynamic Generate rows without using loops
How to dynamic generate row from max value for example if i am passing max value 7 Store procedure should return value 1 2 3 4 5 6 7 without using loops Answer
From 2 tables, get rows unique to each table
Starting with 2 tables, I want to get all rows with value in a certain column(cName) that is present on 1 table but not the other. I want to do this for both tables. I found a solution to use LEFT JOIN which gives me solution for 1 of the tables and I used UNION to combine. Is this a
Calculate time difference between two records and insert into another table if difference is greater than 30 seconds
I have the following table Tran_DeviceAttRec table: I want to select and insert only those fields which time difference is more than 30 second into temp table for example if emp_id 2 punchdate is 2021-02-01 16:52:48.000 and Dev_direction is IN and the same emp_id 2 punchdate is 2021-02-01 16:52:54.000 and Dev…
Get max of sum during joining two tables
I want to get the subscriber that has maximum value of Bill (Total Bill). I tried using the following script but SQL did not execute successflly. Please help me on what I did wrong on this. I have 2 tables: Subscriber FirstName MIN Ben 258999542 Reed 458524896 Steve 586692155 Clint 1007772121 Frank 1287548752…
Retrieve substring of a column name, then apply them to corresponding column data? SQL
I have a table with, let’s say, 13 columns. I need to take a part of the column name and apply it to the corresponding data in two columns. Example of what I start with: Class Result01 Result02 …
SQL Pivot and get column row data
I have tables and data as below. Trying to get the Manufacturer and the questions they answered by joining and pivot but able to. Added the expected output at the end but no luck. Any suggestions are …
How to Select one Value for each row after Joining of 2 Tables
I have 2 tables, the first one has 10 distinct values: , each GlobalPnID has many values on the second table, I want to join 2 tables and select one random value of PortionKey of the second table that match the condition and move to the next GlobalPnID Answer