Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I have a table that is full of bit and int fields.
Any bit field has a same field as int , and it means every field that is true, so users need that item(request) ,and int field, means how many of that item they need.


like This :

SQL
CREATE TABLE [dbo].[tRequest](
    [RequestID] [int] IDENTITY(1001,3) NOT NULL,
    [UserID] [int] NULL,
    [ProductCatalog] [bit] NULL,
    [ProCatCount] [int] NULL,
    [SeminarDVD] [bit] NULL,
    [SeminarDVDCount] [int] NULL,
    [LenzTester] [bit] NULL,
    [LenzTesterCount] [int] NULL,
    [TrainCD] [bit] NULL,
    [TrainCDCount] [int] NULL,
    [AirAqua] [bit] NULL,
    [AirAquaCount] [int] NULL,
    [AirAstigma] [bit] NULL,
    [AirAstigmaCount] [int] NULL,
    [SoloAqua] [bit] NULL,
    [SoloAquaCount] [int] NULL,
    [FreshLook] [bit] NULL,
    [FreshLookCount] [int] NULL,
    [IcooneBrosh] [bit] NULL,
    [IcooneBroshCount] [int] NULL,
    [IcoonePro] [bit] NULL,
    [IcooneProCount] [int] NULL,
    [IcoondeCD] [bit] NULL,
    [IcooneCDCount] [int] NULL,
    [PDate] [nvarchar](50) NULL,
    [BroshStand] [bit] NULL,
    [BroshStandCount] [int] NULL,
    [LamaStandAqua] [bit] NULL,
    [LamaStandAquaCount] [int] NULL,
    [LamaStandFresh] [bit] NULL,
    [LamaStandFreshCount] [int] NULL,
 CONSTRAINT [PK_tRequest] PRIMARY KEY CLUSTERED
(
    [RequestID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tRequest]  WITH CHECK ADD  CONSTRAINT [FK_tRequest_TAccount1] FOREIGN KEY([RequestID])
REFERENCES [dbo].[TAccount] ([AccountID])
GO

ALTER TABLE [dbo].[tRequest] CHECK CONSTRAINT [FK_tRequest_TAccount1]
GO



I want to have a query that can select just that bit and int fields that the bit one is true.

Any suggestion?

Thanks in Advance.
Posted
Updated 27-Jun-11 0:19am
v2
Comments
CS2011 27-Jun-11 7:07am    
Can you explain a bit more what you want
arminamini 27-Jun-11 7:57am    
Thanks for ur notice.
For example i have a row in this table with these values for these fields :
ProdactCatalog : True
ProdactCatalogCount : 3

SeminarDVD : False
SeminarDVDCount : 0

,....

I want to write a query that dont show false fields,and their count fields too.
just Select true fields and their count in a select query.
Thanks in Advance.
[no name] 27-Jun-11 7:24am    
i can't understand your requirement my friend, could you please add some more information
arminamini 27-Jun-11 7:57am    
Thanks for ur notice.
For example i have a row in this table with these values for these fields :
ProdactCatalog : True
ProdactCatalogCount : 3

SeminarDVD : False
SeminarDVDCount : 0

,....

I want to write a query that dont show false fields,and their count fields too.
just Select true fields and their count in a select query.
Thanks in Advance.

1 solution

That's a horrible table. If you can change it's structure, it'd be best to do so.

tRequest
RequestId

tItems
ItemName (e.g., Seminar)
ItemCount (e.g., 10)

That would also simplify your query.
 
Share this answer
 
Comments
arminamini 28-Jun-11 2:16am    
Yes, i know it's not a normal table, but i dont know if i can change it. i just wondering if there is a way to select those fields.
anyway, thanks for ur answer, i think i should change it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900