dynamic-pivot

Storing dynamic Pivot result into a temporary table in SQL Server

ε祈祈猫儿з 提交于 2021-02-05 07:18:45
问题 I have the following schema and sample data. create table MyTable ( Id int, Year int, Channel varchar(10), Payments int ) insert into MyTable values (1,2012,'HV',100), (1,2014,'HV',56), (2,2012,'NL',17000) (2,2012,'HV',495), (3,2013,'HV',565) Now I want to create and insert dynamic pivot data in a temporary table. I am able to create the pivot data as the demo here. But I want to store this data into a temporary table. What I have tried is as below. Declare @SQL varchar(max) = ' if object_id(

Dynamic Pivot Query using Sql Developer Oracle

喜夏-厌秋 提交于 2021-01-29 07:09:12
问题 Initial table students NAME School Class John Hs English Steve Hs Maths Matthew Hs Science Jim Hs History Output Needed: I need the query to auto pick up Name column data from initial table and change it to column headers in output and since the names will continuously change i cannot hard code the names using simple pivot query. I am new to pivot queries so I wanted to request if someone can help me out. Thank You. School John Steve Matthew Jim Hs English Maths Science History Here's what i

PIVOT Query multiple joining

霸气de小男生 提交于 2020-06-17 06:21:55
问题 I have three tables as below. submission1_header Submission1_id Submission2_id Name 100 500 Rahul 200 500 Deva submission1_details Submission1_id Submission2_id Question_no Answer 100 500 1 YES 100 500 2 YES 100 500 3 NO 100 500 4 NO 100 500 5 YES 200 501 1 YES 200 501 3 YES 200 501 4 YES submission2_details Submission2_id Question_no Answer 500 1 YES 500 2 YES 501 1 YES 501 2 YES 501 3 NA Using below query I got the output as below (which is joining first two tables only) =================

SQL SERVER Replacing the null value in dynamic PIVOT

筅森魡賤 提交于 2020-01-06 08:00:43
问题 Good day/night to all. I'm new in stored procedure, i have lack of experience and understanding when it comes to stored procedure. I tried the other tutorial and answers but i don't know why my query wasnt working when using isnull(payment,'0') or coalesce(payment,'0'). declare @sql as nvarchar(max) = '[2013-04-01],[2013-04-02],[2013-04-03],[2013-04-04],[2013-04-05],[2013-04-06]'; declare @name as nvarchar(max) = 'Derichel' set @sql = 'SELECT pid, [Fullname], ' + @sql + ' FROM (SELECT pid,