我如何...在sql server中动态提供年龄类别 [英] How do I...provide category for age dynamically in sql server

查看:113
本文介绍了我如何...在sql server中动态提供年龄类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个网页,将在数据库中存储



用户年龄





i希望根据年龄,成人,年龄基于他/她的年龄进入的年龄为用户提供类别动态我如何实现这一目标



html:

name:< input type =textid =txtname>

age:< input type =textid =txtage >



如果用户输入年龄18我想在数据库中为他分配类别dyanamically我该怎么办??????????

i developed a web page which will store

User age

in database

i want to give category for user according to the age he is entering like young,adult,old based on his/her age dynamically how can i achieve thisone

html:
name:<input type="text" id="txtname">
age:<input type="text" id="txtage">

if user enter age 18 i want to assign category to him in database dyanamically how can i do??????????

推荐答案

你的表结构将是:



AgeCategory

You table structure would be:

AgeCategory
ID(PK) -- Category<br />
1 -- Young<br />
2 -- Adult<br />
3 -- Old





用户



User

ID(PK) -- Name -- AgeCategoryId(FK to the AgeCategory)<br />
1 -- ABC -- 1<br />
2 -- WER -- 2<br />
3 -- RTY -- 2<br />
4 -- FGH -- 1<br />
5 -- SDF -- 3





您还没有指定使用哪种技术插入从HTML到DB的数据,我们无法真正帮助。但伪代码将是,



And you haven't specified which technology are you using for inserting the data from the HTML to DB, we can't really help on that. But the pseudo code would be,

if(txtage < 18)<br />
    // category 1 - young<br />
else if(txtage >= 18 && txtage <= 60)<br />
    // category 2 - adult<br />
else<br />
    // category 3 - old<br />
<br />
// and the fire the INSERT statement for the User table<br />







-KR




-KR


使用 案例查询..



Use Case query..

create table categorys(age bigint,category nvarchar(15))
insert into categorys values(12,case when 12<8 then 'children' when 12<18 then 'Not adult' when 12>18 then 'adult'  end )
select * from categorys


这篇关于我如何...在sql server中动态提供年龄类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆