I have an Employee table with these columns : EmployeeId Fullname Phone Department Team Function Manager and EmployeeHistory containing the history with different columns, but there are some in common : EmployeeId Fullname Email Geolocation Department Team Function Manager How can I union them? Answer Replace…
Tag: sql-server
Creating Dynamic SQL Query to join multiple tables?
I have a dataset in SQl which includes huge numbers of tables (more than 2000). Within these tables, I have a main table called ‘main_table’, that includes some parameters and one of them is the key named ‘id’. I have also a table called ‘Tables_name’, which consists of the…
Dynamic SQL stored procedure and datetime
I have a simple query that I want to convert to dynamic SQL. I have 2 input parameters: a table and a datetime. And the output is the rowcount for the table and this specific datetime. I tried different solutions. I tried the query with execute sp_executesql, I tied to add the the ”’ before and af…
Get multiple clock in and out time from multiple inputs and neglect without clock [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year. Improve this question I have login table structure as below I want to get like Answer As mentioned…
Display null if only one value for Min(Column) and Max(column) SQL query
This is my original table Desired output: Current output with my query Query: Answer You can get your expected output from your sample input: See it in action: SQL Fiddle You should probably add some aliases to at least one set of columns. Not sure, though, how you got two rows of data with your sample query.…
SQL Server: Return a string in a specific format
In TSQL, I need to format a string in a predefined format. For eg: SNO STRING FORMAT OUTPUT 1 A5233GFCOP *XXXXX-XXXXX *A5233-GFCOP 2 K92374 /X-000XXXXX /K-00092374 3 H91543987 XXXXXXXXX H91543987 I am trying with FORMATMESSAGE() built in function. For ex: FORMATMESSAGE(‘*%s-%s’,’A5233′…
Select node from xml nodes
there! there is a small xml. I’m selecting data via And result like this But, need to have one more column with the contents of the entire row, like this Answer Use the query method cc type is XML. db<>fiddle
How to create a Table Type with columns more than 1024 columns
I want to create a table type that should have more than 1024 columns. So I tried to use sparse columns by creating a – SpecialPurposeColumns XML COLUMN_SET as shown below. That did not work. It gave me an error: Incorrect syntax near ‘COLUMN_SET’ Is there any way that I can create a table t…
How to pivot given string by replacing special characters in SQL?
In an interview, I have been asked to pivot a string by replacing special characters. Given string was ‘AAA%BBB$CCC#DDD’ Expected output as shown in then image: How can we do this in SQL Server? Thanks in advance! Answer In SQL Server 2014?(I guess the operating system you are using is Windows Ser…
SQL – Combine two rows if difference is below threshhold
I have a table like this in SQL Server: What I would like to have is a query that outputs consolidated records based on the time difference between two consecutive records (end_time of row n and start_time row n+1) . All records where the time difference is less than 2 minutes should be combined into one time…