根据动态的年龄组显示结果

时间:2018-04-26 14:15:22

标签: asp.net sql-server-2008

我希望根据值显示数据,如果成员年龄为18岁,如果年龄为27岁则属于11-20岁年龄组,如果年龄为16岁则为21-30岁,等于11-20岁等等。这里所有年龄组都是代码`BEGIN

INSERT INTO#temp3 从Split中选择项目(@ageGroup,&#39 ;;')

插入#FacilityWiseAges      选择um.ID作为memberId,um.groups作为组(选择*来自#temp3,udv_Members)作为um

WHERE DATEDIFF(MONTH,DOB,GETDATE())/12 <= SUBSTRING(@ldata, 0, CHARINDEX('-',@ldata))     
OR   DATEDIFF(MONTH,DOB,GETDATE())/12 >= SUBSTRING(@ldata, CHARINDEX('-',@ldata) + 1, LEN(@ldata))

FETCH NEXT FROM detail zh INTO @ldata 结束 关闭细节; DEALLOCATE详细信息;

Select Distinct  um.MemberName,
                 um.ID, 
                 um.BillingModeId, 
                 um.BillingModeName, 
                 um.MembershipTypeID, 
                 um.MembershipType,
                 DATEDIFF(MONTH,DOB,GETDATE())/12 as MemberAge,
                 SUBSTRING(fac.Name,CHARINDEX('-',fac.Name + '-')+1,LEN(fac.Name)) as FacilityName,
                 fac.MinimumAge as FacilityAgeFrom, 
                 fac.MaximumAge as FacilityAgeTo,
                 Convert(nvarchar(max),fac.MinimumAge) + ' - ' + Convert(nvarchar(max),fac.MaximumAge) as Default_FacilityAgeGroup,fages.groups

from udv_Members um 
LEFT JOIN #FacilityWiseAges fages on fages.memberID = um.ID
INNER JOIN [dbo].[tbl_Bills] bill on bill.MemberID = um.ID
INNER JOIN [dbo].[udv_MembershipTypes] mt on mt.ID = um.MembershipTypeID
INNER JOIN [dbo].[tbl_BillingModes] AS bm ON bm.ID = [dbo].[udf_BillingModeByMembershipTypeID] (mt.ID)
INNER JOIN [dbo].[tbl_Bills_FacilityContractDetails] as fcb on fcb.BillID = bill.ID
INNER JOIN [dbo].[tbl_Facilities_Contract_Details] as fcd on fcd.ID = fcb.ContractDetailID 
INNER JOIN [dbo].[tbl_Facilities_Branches_Durations_Rates] fc on fc.ID = fcd.RateID 
INNER JOIN [dbo].tbl_Facilities_Branches_Durations as fdc on fdc.ID=fc.FacilityBranchGenderDurationID
INNER JOIN [dbo].[tbl_Facilities_Branches_Genders] gb on gb.ID = fdc.FacilityBranchGenderID
INNER JOIN [dbo].[tbl_Facilities_Branches] AS bab ON bab.ID =gb.FacilityBranchID
INNER JOIN [dbo].[udv_Facilities] AS fac ON fac.ID = bab.FacilityID
INNER JOIN [dbo].[tbl_Member_Ledger] ledger ON ledger.MemberLedgerId = bill.MemberLedgerID
INNER JOIN dbo.tbl_TransactionType AS t ON t.ID = ledger.TransactionTypeID

删除表#temp3 删除表#FacilityWiseAges`

1 个答案:

答案 0 :(得分:0)

我假设通过标记asp.net,你正在进行sqlconnection sqlcommand.executereder调用。

执行sqlcommand.executereader调用后,将返回的datareader保存到gridview.datasource中。然后调用GridView.Databind()实际将命令发送到服务器并接收返回的表。

要解决您的问题,请执行以下操作:

根据您的SQL命令,您获得的结果将像excel表一样保存到gridview中。

然后,您的SQL Server服务器的结果将被解释并可访问:

在这个例子中我使用的是这个表:

a b c d e f g

a b c d e f g

a b c d e f g

a b c d e f g

所以,我们有4行7列。

使用GridView.Rows(行索引).Cells(列索引).Text我们可以将字符串数据作为字符串获取。示例:GridView.Rows(0).Cells(2).Text返回c(第1行,第3列)。 GridView.Rows(1).Cells(4).Text返回e(第2行,第5列)。

您的选择列顺序指定列的顺序。知道了,你可以要求年龄。如果我们假设a代表年龄,我们可以这样做:

If CInt(GridView.Row(0).Cells(0).Text) > 11 and CInt(GridView.Row(0).Cells(0).Text) < 20 Then
    //your code
end if

继续其他年龄的if语句并在那里指定您的特殊代码。

此致

尼汝