TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Josephs
679
1.2k
42.5k
How to Join Multiple Table using Pivot.
Oct 18 2012 12:21 PM
I need How to Join Multiple Tables but sum function populate no question show like this n/a
see below text File.(Details)
Execute Thisl Query First
[CODE]
[CODE]
Step 1 -> Execute this Query
===============================
USE [Test]
GO
/****** Object: Table [dbo].[TableQ3000] Script Date: 10/18/2012 17:47:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableQ3000](
[Id] [int] IDENTITY(1,1) NOT NULL,
[QText] [nvarchar](max) NULL,
[QCode] [nvarchar](50) NULL,
[Code] [int] NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TableQ3000] ON
INSERT [dbo].[TableQ3000] ([Id], [QText], [QCode], [Code]) VALUES (1, N'India is Big Country?', N'Q1', 6)
INSERT [dbo].[TableQ3000] ([Id], [QText], [QCode], [Code]) VALUES (2, N'India is Peaceful Country?', N'Q2', 4)
INSERT [dbo].[TableQ3000] ([Id], [QText], [QCode], [Code]) VALUES (4, N'India is Welathy Country?', N'Q4', 1)
SET IDENTITY_INSERT [dbo].[TableQ3000] OFF
/****** Object: Table [dbo].[TableQ2000] Script Date: 10/18/2012 17:47:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableQ2000](
[Id] [int] IDENTITY(1,1) NOT NULL,
[QText] [nvarchar](max) NULL,
[QCode] [nvarchar](50) NULL,
[Code] [int] NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TableQ2000] ON
INSERT [dbo].[TableQ2000] ([Id], [QText], [QCode], [Code]) VALUES (1, N'India is Big Country?', N'Q1', 6)
INSERT [dbo].[TableQ2000] ([Id], [QText], [QCode], [Code]) VALUES (3, N'India is PowerFul Country?', N'Q3', 3)
INSERT [dbo].[TableQ2000] ([Id], [QText], [QCode], [Code]) VALUES (5, N'India is strong Country?', N'Q5', 2)
SET IDENTITY_INSERT [dbo].[TableQ2000] OFF
/****** Object: Table [dbo].[TableQ1000] Script Date: 10/18/2012 17:47:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableQ1000](
[Id] [int] IDENTITY(1,1) NOT NULL,
[QText] [nvarchar](max) NULL,
[QCode] [nvarchar](50) NULL,
[Code] [int] NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TableQ1000] ON
INSERT [dbo].[TableQ1000] ([Id], [QText], [QCode], [Code]) VALUES (1, N'India is Big Country?', N'Q1', 6)
INSERT [dbo].[TableQ1000] ([Id], [QText], [QCode], [Code]) VALUES (2, N'India is Peaceful Country?', N'Q2', 4)
INSERT [dbo].[TableQ1000] ([Id], [QText], [QCode], [Code]) VALUES (3, N'India is PowerFul Country?', N'Q3', 3)
INSERT [dbo].[TableQ1000] ([Id], [QText], [QCode], [Code]) VALUES (4, N'India is Welathy Country?', N'Q4', 1)
INSERT [dbo].[TableQ1000] ([Id], [QText], [QCode], [Code]) VALUES (5, N'India is strong Country?', N'Q5', 2)
SET IDENTITY_INSERT [dbo].[TableQ1000] OFF
/****** Object: Table [dbo].[TableA3000] Script Date: 10/18/2012 17:47:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableA3000](
[AId] [bigint] IDENTITY(1,1) NOT NULL,
[Q1] [nvarchar](50) NULL,
[Q2] [nvarchar](50) NULL,
[Q4] [nvarchar](50) NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TableA3000] ON
INSERT [dbo].[TableA3000] ([AId], [Q1], [Q2], [Q4]) VALUES (1, N'65', N'1', N'0')
INSERT [dbo].[TableA3000] ([AId], [Q1], [Q2], [Q4]) VALUES (2, N'1', N'2', N'0')
INSERT [dbo].[TableA3000] ([AId], [Q1], [Q2], [Q4]) VALUES (3, N'2', N'1', N'1')
SET IDENTITY_INSERT [dbo].[TableA3000] OFF
/****** Object: Table [dbo].[TableA2000] Script Date: 10/18/2012 17:47:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableA2000](
[AId] [bigint] IDENTITY(1,1) NOT NULL,
[Q1] [nvarchar](50) NULL,
[Q3] [nvarchar](50) NULL,
[Q5] [nvarchar](50) NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TableA2000] ON
INSERT [dbo].[TableA2000] ([AId], [Q1], [Q3], [Q5]) VALUES (1, N'65', N'2', N'2')
INSERT [dbo].[TableA2000] ([AId], [Q1], [Q3], [Q5]) VALUES (2, N'1', N'2', N'1')
INSERT [dbo].[TableA2000] ([AId], [Q1], [Q3], [Q5]) VALUES (3, N'2', N'1', N'2')
SET IDENTITY_INSERT [dbo].[TableA2000] OFF
/****** Object: Table [dbo].[TableA1000] Script Date: 10/18/2012 17:47:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableA1000](
[AId] [bigint] IDENTITY(1,1) NOT NULL,
[Q1] [nvarchar](50) NULL,
[Q2] [nvarchar](50) NULL,
[Q3] [nvarchar](50) NULL,
[Q4] [nvarchar](50) NULL,
[Q5] [nvarchar](50) NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TableA1000] ON
INSERT [dbo].[TableA1000] ([AId], [Q1], [Q2], [Q3], [Q4], [Q5]) VALUES (1, N'65', N'1', N'2', N'0', N'2')
INSERT [dbo].[TableA1000] ([AId], [Q1], [Q2], [Q3], [Q4], [Q5]) VALUES (2, N'1', N'2', N'2', N'0', N'1')
INSERT [dbo].[TableA1000] ([AId], [Q1], [Q2], [Q3], [Q4], [Q5]) VALUES (3, N'2', N'1', N'1', N'1', N'2')
INSERT [dbo].[TableA1000] ([AId], [Q1], [Q2], [Q3], [Q4], [Q5]) VALUES (4, N'1', N'1', N'2', N'0', N'1')
INSERT [dbo].[TableA1000] ([AId], [Q1], [Q2], [Q3], [Q4], [Q5]) VALUES (5, N'2', N'2', N'0', N'0', N'2')
SET IDENTITY_INSERT [dbo].[TableA1000] OFF
[/CODE]
Step2-See Below attachment Image File.Above query execute and showing like this.
=============================================================================
[/CODE]
Attachment:
i need outputthis.zip
Reply
Answers (
1
)
How to write the Pivot Query For This Sql Server
sql connection String