December 7, 2010 at 1:28 pm
USE [GamitOlap]
GO
/****** Object: Table [dbo].[testSales] Script Date: 12/07/2010 13:32:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[testSales](
[yrm] [int] NOT NULL,
[part] [varchar](50) NOT NULL,
[sales] [int] NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [GamitOlap]
GO
/****** Object: Table [dbo].[testTally] Script Date: 12/07/2010 13:32:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[testTally](
[yrm] [int] NOT NULL
) ON [PRIMARY]
GO
insert into testTally (yrm) values (1)
insert into testTally (yrm) values (2)
insert into testTally (yrm) values (3)
insert into testSales (yrm,part,sales)
values (1,'A',32)
insert into testSales (yrm,part,sales)
values (2,'A',48)
insert into testSales (yrm,part,sales)
values (2,'b',52)
insert into testSales (yrm,part,sales)
values (3,'b',68)
select ISNULL(B.sales,0) as sales
from(SELECT TOP (100) PERCENT sales, part, yrm FROM dbo.testsales WHERE (part = 'A') ) as B right outer join testtally on B.yrm = testtally.yrm order by testtally.yrm
select ISNULL(B.sales,0) as sales
from(SELECT TOP (100) PERCENT sales, part, yrm
FROM dbo.testsales ) as B right outer join testtally on B.yrm = testtally.yrm order by testtally.yrm
December 7, 2010 at 3:59 pm
From your post I'm not too sure what the problem is or what you are expecting as results. Everything else we need to help is there.
December 7, 2010 at 4:14 pm
Question is a duplicate, please direct all commentary and responses to the following post:
http://www.sqlservercentral.com/Forums/Topic1031483-392-1.aspx
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply