I have two tables as below. I want to join these two tables and need to set the column values of second table as column header as shown below. How can I achieve this? Table1 table2 The output table should be Answer You can use Dynamic Pivot as below-
“Distinct” results in complex query
I have the following query, which returns all merchants in the database who have transactions between two given dates. But, there is additional information I need to include in the query. I’ve written the enhanced query below, but it results in duplicated merchants. I know the query could be written better, but that’s the limit of my SQL knowledge. I
HIDE Column in Select query?
Hi I’m trying to hide the TotalRank Column that gets displayed during my results because I only needed it in this query to help sort items. I don’t need this information displayed. Answer You can use th following
Oracle birthday column regex constrain violated
I want all my dates in my database in the following yyyy-mm-dd date format. For example, ‘2020-05-28’. But this doesn’t seem to work as I thought it would when I insert a date into my User table which …
SQL Joining of Multiple Tables
SQL newbie here, I am trying to have the table print out the sum of the wages, make, and car model for all the people that own a particular make/model combination. As of right now, the table prints …
C# application with SQL Server stored procedure
My C# Windows form has a combobox and textbox. The combobox has 2 records which are ‘Novel’ & ‘Poem’. I need to write code that if I select ‘Poem’, it should be auto generate ‘PO-00001’ and if I select ‘Novel’, it should be auto generate ‘NV-00001’. So then I wrote a stored procedure to do that and it looks like
Extract string between two characters in a string
I have a set of strings that has datetime values and I would like to extract them. I am not sure if this is even possible using T-SQL. Expected Results: Answer For this dataset, string functions should do it: The idea is to count backwards from the end of the string, and capture the 14 characters that preced the extension
How to update row if exist and meet more than one condition and insert it otherwise in SQL Server
I’m trying to perform the below code which I have found it in a thread here The problem is that I need to do the same thing but with the SQL Server query. My main thought here is that if the new read has the same BoxNo and the same SSCC and the same StyleBarcode, then the value in Qty
SQL Query to get 2nd most recent results with multiple columns
I am trying to obtain the 2nd most recent results for all distinct part_id’s(based off of order_date) to go into a report I am working on making to compare it to the most recent results. The commented sections are from another approach I was trying but unsuccessful with. Any help is greatly appreciated! (Side note: I am new to posting
Count the number of appearances of char given a ID
I have to perform a query where I can count the number of distinct codes per Id. The output should be something like: Can you give me some advise on this? Answer If the codes are only to the provided ones, the following query can provide the desired result. Note: as I can see from sample input data, code ‘I’