Sunday, February 19, 2012

help

Hi

If i use select * from table...i get the following

10 Energy Energy Energy Equipment & Services Oil & Gas
Drilling10101010
10 Energy Energy Energy Equipment & Services Oil & Gas
Equipment & Svcs10101020
10 Energy Energy Oil & Gas Integrated Oil &
Gas10102010
10 Energy Energy Oil & Gas Oil & Gas
Exploration & Prod10102020
10 Energy Energy Oil & Gas Oil & Gas Refining
& Mktg10102030
10 Energy Energy Oil & Gas Oil & Gas Storage
& Transpor10102040
10 Energy Energy Oil & Gas Coal & Consumable
Fuels10102050
15 Materials Materials Chemicals Commodity
Chemicals15101010
15 Materials Materials Chemicals Diversified
Chemicals15101020
15 Materials Materials Chemicals Fertilizers & Agri
Chemicals15101030
15 Materials Materials Chemicals Industrial
Gases15101040
15 Materials Materials Chemicals Specialty
Chemicals15101050
15 Materials Materials Construction Materials Construction
Materials15102010
15 Materials Materials Containers & Packaging Metal & Glass
Containers15103010
15 Materials Materials Containers & Packaging Paper
Packaging15103020
15 Materials Materials Metals & Mining
Aluminum15104010
15 Materials Materials Metals & Mining Diversified Metals
& Mining15104020
15 Materials Materials Metals & Mining Gold15104030
15 Materials Materials Metals & Mining Precious Metals &
Minerals15104040
15 Materials Materials Metals & Mining Steel15104050
15 Materials Materials Paper & Forest Products Forest
Products15105010
15 Materials Materials Paper & Forest Products Paper
Products15105020

but my output should be as follows

10 Energy Energy Energy Equipment & Services Oil & Gas
Drilling10101010
Oil & Gas Equipment & Svcs10101020
10 Energy Energy Oil & Gas Integrated Oil &
Gas10102010
Oil & Gas Exploration & Prod10102020
Oil & Gas Refining & Mktg10102030
Oil & Gas Storage & Transpor10102040
Coal & Consumable Fuels10102050
15 Materials Materials Chemicals Commodity
Chemicals15101010
Diversified Chemicals15101020
Fertilizers & Agri Chemicals15101030
Industrial Gases15101040
Specialty Chemicals15101050
15 Materials Materials Construction Materials Construction
Materials15102010
Containers & Packaging Metal & Glass Containers15103010
Paper Packaging15103020
15 Materials Materials Metals & Mining
Aluminum15104010
Diversified Metals & Mining15104020
Gold15104030
Precious Metals & Minerals15104040
Steel15104050
15 Materials Materials Paper & Forest Products Forest
Products15105010
Paper Products15105020

can anyone tell me how 2 query for abovekalikoi@.gmail.com wrote:

> Hi
> If i use select * from table...i get the following
>
> 10 Energy Energy Energy Equipment & Services Oil & Gas
> Drilling10101010
> 10 Energy Energy Energy Equipment & Services Oil & Gas
> Equipment & Svcs10101020
> 10 Energy Energy Oil & Gas Integrated Oil &
> Gas10102010
> 10 Energy Energy Oil & Gas Oil & Gas
> Exploration & Prod10102020
> 10 Energy Energy Oil & Gas Oil & Gas Refining
> & Mktg10102030
> 10 Energy Energy Oil & Gas Oil & Gas Storage
> & Transpor10102040
> 10 Energy Energy Oil & Gas Coal & Consumable
> Fuels10102050
> 15 Materials Materials Chemicals Commodity
> Chemicals15101010
> 15 Materials Materials Chemicals Diversified
> Chemicals15101020
> 15 Materials Materials Chemicals Fertilizers & Agri
> Chemicals15101030
> 15 Materials Materials Chemicals Industrial
> Gases15101040
> 15 Materials Materials Chemicals Specialty
> Chemicals15101050
> 15 Materials Materials Construction Materials Construction
> Materials15102010
> 15 Materials Materials Containers & Packaging Metal & Glass
> Containers15103010
> 15 Materials Materials Containers & Packaging Paper
> Packaging15103020
> 15 Materials Materials Metals & Mining
> Aluminum15104010
> 15 Materials Materials Metals & Mining Diversified Metals
> & Mining15104020
> 15 Materials Materials Metals & Mining Gold15104030
> 15 Materials Materials Metals & Mining Precious Metals &
> Minerals15104040
> 15 Materials Materials Metals & Mining Steel15104050
> 15 Materials Materials Paper & Forest Products Forest
> Products15105010
> 15 Materials Materials Paper & Forest Products Paper
> Products15105020
>
> but my output should be as follows
>
> 10 Energy Energy Energy Equipment & Services Oil & Gas
> Drilling10101010
> Oil & Gas Equipment & Svcs10101020
> 10 Energy Energy Oil & Gas Integrated Oil &
> Gas10102010
> Oil & Gas Exploration & Prod10102020
> Oil & Gas Refining & Mktg10102030
> Oil & Gas Storage & Transpor10102040
> Coal & Consumable Fuels10102050
> 15 Materials Materials Chemicals Commodity
> Chemicals15101010
> Diversified Chemicals15101020
> Fertilizers & Agri Chemicals15101030
> Industrial Gases15101040
> Specialty Chemicals15101050
> 15 Materials Materials Construction Materials Construction
> Materials15102010
> Containers & Packaging Metal & Glass Containers15103010
> Paper Packaging15103020
> 15 Materials Materials Metals & Mining
> Aluminum15104010
> Diversified Metals & Mining15104020
> Gold15104030
> Precious Metals & Minerals15104040
> Steel15104050
> 15 Materials Materials Paper & Forest Products Forest
> Products15105010
> Paper Products15105020
>
> can anyone tell me how 2 query for above

That's just presentational stuff. It is called "banding" in reports and
even the most basic reporting tool will do it for you. There isn't much
cause to do it in SQL and although it is certainly possible it will be
needlessly complex to do and won't perform well.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx
--|||Small nit --

Whenever posting to a newsgroup try using headers a that are more
descriptive than just 'help'. I assume about 95% of
the people posting here require help. This'll make it easier for people
who are browsing old articles.

thanks,

Crazy|||I got four table structures as follows

CREATE TABLE [dbo].[Sector] (
[SectorID] [int] NOT NULL ,
[SectorName] [varchar] (50)
)

the data is as follows
-------
10Energy

CREATE TABLE [dbo].[GroupMaster] (
[SectorID] [int] NOT NULL ,
[GroupID] [int] NOT NULL ,
[GroupName] [varchar] (50)
)

the data is as follows
--------
10 1010 Energy

CREATE TABLE [dbo].[IndustryMaster] (
[GroupID] [int] NOT NULL ,
[IndustryID] [numeric](6, 0) NOT NULL ,
[IndustryName] [varchar] (50)
)

the data is as follows
--------------
1010101010Energy Equipment & Services
1010101020Oil & Gas

CREATE TABLE [dbo].[SubIndustryMaster] (
[IndustryID] [numeric](6, 0) NOT NULL ,
[SubIndustryID] [numeric](8, 0) NOT NULL ,
[SubIndustryName] [varchar] (30)
)

the data is as follows
----------------
10101010101010Oil & Gas Drilling
10101010101020Oil & Gas Equipment & Svcs
10102010102010Integrated Oil & Gas
10102010102020Oil & Gas Exploration & Prod
10102010102030Oil & Gas Refining & Mktg
10102010102040Oil & Gas Storage & Transpor
10102010102050Coal & Consumable Fuels

Now i want a ADO DataShape command which results the following

Energy
Energy
Energy Equipment & Services
Oil & Gas Drilling
Oil & Gas Equipment & Svcs

Oil & Gas
Integrated Oil & Gas
Oil & Gas Exploration & Prod
Oil & Gas Refining & Mktg
Oil & Gas Storage & Transpor
Coal & Consumable Fuels|||(kalikoi@.gmail.com) writes:
> Now i want a ADO DataShape command which results the following
>
> Energy
> Energy
> Energy Equipment & Services
> Oil & Gas Drilling
> Oil & Gas Equipment & Svcs
> Oil & Gas
> Integrated Oil & Gas
> Oil & Gas Exploration & Prod
> Oil & Gas Refining & Mktg
> Oil & Gas Storage & Transpor
> Coal & Consumable Fuels

Hm, maybe you should try an ADO newsgroup. I've read about MS Data Shape,
but I should probably not suggest solutions for it...

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

No comments:

Post a Comment