I have this table Employee_Hire which has Hire date of an employee (ID) in a Department. Now I want to write a Select query which adds one more column (Last_day) to show last day he worked in that …
Tag: tsql
Value from 2nd Row of column copied to 1st row of next column
The table looks like below. I am trying to make 1 new column say SuprerFrez whose value is depends on column FREQHZ. For every UVRID group 2nd value FREQHZ will be 1st value of SuprerFrez and for last FREQHZ, SuprerFrez value will be zero. Expected output with 1 new column whose value depends upon FREQHZ column. Order by FREQHZ ASC
Change date time format from YYY-MM-DD HH:MM:SS to YYYY.MM.DD HH:MM:SS in SQL Server
I have a table with a column RequestDate with following format 2019-12-01 00:00:00:000. I want to see results like this: 2019.12.01 00:00:00:000. I used this command From the above query I am seeing results as 2019.12.01, but I am missing time (00:00:00:000) – how can I keep along with time. I want final results like 2019.12.01 00:00:00:000 Answer I don’t
Sql Syntax to tag rows in a table where this specific criteria appears at least once or more
I am using SQL Server 2014 and I have a table (t1) which contains a list of 6 numbers in more than 25,000 rows. Extract of t1 is given below: Id F1 F2 F3 F4 F5 F6 1 5 11 15 …
SQL Stored Procedures, Combining rows with derived variables
I’ve been away for sometime and need help with, what is probably a simple solution but at this time I’m stuck. I have this select statement and need to combine rows with like elements for the same department but the group by would have a very large select list, is there another way like MERGE? Here is the sql stmt
Include indicator of data present, but not include in results
I can’t quite explain it properly, hence the awful title. As an example, I would have a query that shows customer complaints, of a certain type, and the dates since those complaints. Something like …
SQL: Is there a way to capture “once every 45 days”?
First time post, but I’ve stumbled across Stackoverflow for years. A patient might get a particular lab test many many times in a span of a few months. However, to reduce duplication, I only want to …
Function to convert units based on conversion table
There is a very simple table in the database with metric unit conversions, that looks like: I was thinking about creating a function to convert units that calculates the conversion from the table based on inputs (Unit, FromUnit, ToUnit). For example Conv_Units(0.1, ‘m’, ‘cm’) returns 100. Is this even possible? What I came up with is following, but it does
Loop through a table valued function
I have a table x which has columns y and z it has 10 rows of data. I then have a table-valued function getDetails(y,z) which takes values stored in table x in columns y and z to return a table tb with three columns. I need to write a tsql query that loops values from table x through function getDetails(y,z)to
Insert Select into with same ID
Insert Split Delimited Strings in a Column with same ID. Lets say I have demo setup as follows: I declare some variables Note: the @addresses sting is dynamic and not fixed Now my aim is to insert into table EMPLOYEEID_Address multiple address with same the id using the STRING_SPLIT function. So I tried: But this didn’t work, while works with