in Education by
I have a table which looks like this EmployeeID | Name | Check Date | Check Num | Check Amount | Quarter 1 | Test | 01/21/2018 | 001231312 | 500 | 1 1 | Test | 03/01/2018 | 001233210 | 100 | 1 1 | Test | 05/01/2018 | 123213321 | 13 | 2 1 | Test | 08/01/2018 | 321909900 | 321 | 3 1 | Test | 12/01/2018 | 321000132 | 123 |4 i need to display the following output EmployeeID | Name | 1st Quarter Date | 1st Quarter Check Num | 1st Quarter Check Amount | 2nd Quarter Date | 2nd Quarter Check Num | 2nd Quarter Check Amount | 3rd Quarter Date | 3rd Quarter Check Num | 3rd Quarter Check Amount | 4th Quarter Date | 4th Quarter Check Num | 4th Quarter Check Amount I was researching into this and I found information on using Pivot but it was unclear when it came to displaying details instead of some aggregate of the columns. Thanks JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The easiest way to do this in my opinion would be to use Datepart(QUARTER, Check Date) combined with a case statement. Example: Select EmployeeID , Name , CASE WHEN Datepart(QUARTER, CheckDate) = 1 Then 'Check Date' END AS '1st Quarter Date' , CASE WHEN Datepart(QUARTER, CheckDate) = 1 Then 'Check Num' END AS '1st Quarter Check Num' , CASE WHEN Datepart(QUARTER, CheckDate) = 1 Then 'Check Amount' END AS '1st Quarter Check Amount' , CASE WHEN Datepart(QUARTER, CheckDate) = 2 Then 'Check Date' END AS '2nd Quarter Date' , CASE WHEN Datepart(QUARTER, CheckDate) = 2 Then 'Check Num' END AS '2nd Quarter Check Num' , CASE WHEN Datepart(QUARTER, CheckDate) = 2 Then 'Check Amount' END AS '2nd Quarter Check Amount' , CASE WHEN Datepart(QUARTER, CheckDate) = 3 Then 'Check Date' END AS '3rd Quarter Date' , CASE WHEN Datepart(QUARTER, CheckDate) = 3 Then 'Check Num' END AS '3rd Quarter Check Num' , CASE WHEN Datepart(QUARTER, CheckDate) = 3 Then 'Check Amount' END AS '3rd Quarter Check Amount' , CASE WHEN Datepart(QUARTER, CheckDate) = 4 Then 'Check Date' END AS '4th Quarter Date' , CASE WHEN Datepart(QUARTER, CheckDate) = 4 Then 'Check Num' END AS '4th Quarter Check Num' , CASE WHEN Datepart(QUARTER, CheckDate) = 4 Then 'Check Amount' END AS '4th Quarter Check Amount' From YourTableName I am sure there are cleaner ways to do this and I'm sure others will chime in. Also, please not I did not use the same Column names in Datepart, I believe you will need to '' due to the space (Datepart(QUARTER, 'Check Date'). EDIT: OP added some sample data and since there is a 'Quarter' Column, we can change the Case statement to: CASE WHEN QUARTER = 1 Then .... CASE WHEN QUARTER = 2 Then .... CASE WHEN QUARTER = 3 Then .... CASE WHEN QUARTER = 4 Then ....

Related questions

0 votes
    I have a table which looks like this EmployeeID | Name | Check Date | Check Num | Check Amount | ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have this table which stores containers by region and the number of coffee pouches in each of the containers. if object_id( ... = 1 ) as sq1 ) as sq2 where sq2.LagRunningTotal...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Bile salts (a) breakdown polypeptide chains (b) emulsify fats and solubilise them (c) digest fats ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 8, 2021 in Education by JackTerrance
0 votes
    Will dielectric breakdown lead to formation of magnetic monopole? (a) Yes (b) No This ... proposed by,electromagnetic theory engineering physics,electromagnetic theory nptel...
asked Nov 6, 2021 in Education by JackTerrance
0 votes
0 votes
    In _________________ attacks, the attacker manages to get an application to execute an SQL query created by ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    An application developer can guard against certain snapshot anomalies by appending a ______ clause to the SQL ... topic in section Concurrency Control of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    The condition for a quarter wave transformer is (a) Zo^2 = Zin ZL (b) Zo = Zin ZL ... theory proposed by,electromagnetic theory engineering physics,electromagnetic theory nptel...
asked Nov 6, 2021 in Education by JackTerrance
0 votes
    The quarter wave transformer can be considered as a (a) Impedance inverter (b) Impedance doubler ... by,electromagnetic theory engineering physics,electromagnetic theory nptel...
asked Nov 6, 2021 in Education by JackTerrance
0 votes
0 votes
    A sine wave completes quarter cycle in ____ radians. (a) 2π (b) π (c) π/2 (d) π/4 The question ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 19, 2021 in Education by JackTerrance
0 votes
    IN and NOT IN operations decreases the performance of an SQL query compared to AND/OR operations. it it True or False? a. True b. False...
asked Feb 19, 2023 in Technology by JackTerrance
...