Click here to Skip to main content
15,887,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi
i have five colums which has data type int, i have selected row on the basis of primary key, but now in this row i want to select particular column with name which has value less than some int value.

the resulted column is any in this five column

please help me i find no solution for that on google also i have that table i want to select the column name (which is one among first age,second age,thirdage,fourth age,fifth age) which has the value let assume <20


SQL
USE [MedicalLabDB]
GO
/****** Object:  Table [dbo].[Advance_Sub_Tests]    Script Date: 01/11/2012 15:33:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Advance_Sub_Tests](
	[Advance_Sub_Test_ID] [int] IDENTITY(1,1) NOT NULL,
	[Sub_Test_ID] [int] NULL,
	[L_Bound_M_LessThan_First_Age ] [float] NULL,
	[U_Bound_M_LessThan_First_Age ] [float] NULL,
	[L_Bound_M_LessThan_Second_Age] [float] NULL,
	[U_Bound_M_LessThan_Second_Age] [float] NULL,
	[L_Bound_M_LessThan_Third_Age] [float] NULL,
	[U_Bound_M_LessThan_Third_Age] [float] NULL,
	[L_Bound_M_LessThan_Fourth_Age] [float] NULL,
	[U_Bound_M_LessThan_Fourth_Age] [float] NULL,
	[L_Bound_M_LessThan_Fifth_Age] [float] NULL,
	[U_Bound_M_LessThan_Fifth_Age] [float] NULL,
	[L_Bound_F_LessThan_First_Age] [float] NULL,
	[U_Bound_F_LessThan_First_Age] [float] NULL,
	[L_Bound_F_LessThan_Second_Age] [float] NULL,
	[U_Bound_F_LessThan_Second_Age] [float] NULL,
	[L_Bound_F_LessThan_Third_Age] [float] NULL,
	[U_Bound_F_LessThan_Third_Age] [float] NULL,
	[L_Bound_F_LessThan_Fourth_Age] [float] NULL,
	[U_Bound_F_LessThan_Fourth_Age] [float] NULL,
	[L_Bound_F_LessThan_Fifth_Age] [float] NULL,
	[U_Bound_F_LessThan_Fifth_Age] [float] NULL,
	[First_Age] [int] NULL,
	[Second_Age] [int] NULL,
	[Third_Age] [int] NULL,
	[Fourth_Age] [int] NULL,
	[Fifth_Age] [int] NULL,
	[Test_Active] [bit] NULL,
	[Version] [timestamp] NULL,
 CONSTRAINT [PK_Advance_Sub_Test_1] PRIMARY KEY CLUSTERED 
(
	[Advance_Sub_Test_ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Posted
Updated 10-Jan-12 23:39pm
v3
Comments
Prasad_Kulkarni 11-Jan-12 4:59am    
Hi,am not getting clear picture for your question can you post your code so it will become more clear.
Slacker007 11-Jan-12 5:38am    
@Vishwajeet: I deleted your comment and pasted the code block into your original question. Good luck.
Amir Mahfoozi 11-Jan-12 6:31am    
Please provide numerical example.

1 solution

what about: (this will unfortunately return the same row repeatedly, as many times as what there are age-columns < 20, but the last column (AgeGroup) will tell you which 'age' was < 20...)
SQL
SELECT *, 'First_Age' as 'AgeGroup'
FROM [dbo].[Advance_Sub_Tests]
WHERE First_Age < 20
UNION ALL
SELECT *, 'Second_Age' as 'AgeGroup'
FROM [dbo].[Advance_Sub_Tests]
WHERE Second_Age < 20
UNION ALL
SELECT *, 'Third_Age' as 'AgeGroup'
FROM [dbo].[Advance_Sub_Tests]
WHERE Third_Age < 20
UNION ALL
SELECT *, 'Fourth_Age' as 'AgeGroup'
FROM [dbo].[Advance_Sub_Tests]
WHERE Fourth_Age < 20
UNION ALL
SELECT *, 'Fifth_Age' as 'AgeGroup'
FROM [dbo].[Advance_Sub_Tests]
WHERE Fifth_Age < 20
 
Share this answer
 
v2

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