how to declare a variable

  • Hi....

    Iam having two tables in that first table consists of id,name,age,gender,and so on...

    and in second table it consists of id,gender,maturnity(is nothing but age) disease type and so on...

    in the first we will give age as 13,14,18,19 and so on and in second table we will give adult or child if the age is above 18 then it should get the diseases for above 18 years from the second table or else we should get child diseases. How to do this can any one help me its urgent...........thanks in advance:-)

  • please anyone help me yar how to declare a variable for comparing ages...:-)

  • Your question iss not clear.

    Can you give samples with statements?

  • you should read the following

    How to post data/code on a forum to get the best help[/url]

    Give your question a chance of being answered correctly.

  • table1 table2

    id id

    age maturinty(is nthg but age)(but we will give only adult and child)

    gender gender

    type

    these are two tables we are having.

    1. In the first table we will give age as 13,18 in numeric form but in the second table we will give as adult or child.

    2. our requirement is we should compare the two tables if the age in the first table is above 18 then we should the list from the second table what are the types available for adults.

    3. If not if the age is below 18 then from the second table we should get the types available for child.

  • You can use check constrain.

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • i cant understand what u are saying

  • ashalatha.cse76 (4/16/2014)


    i cant understand what u are saying

    i also cant understand what u r saying, still i tried the following:

    Declare @Table1 table

    (

    ID int

    , Age int

    , gender varchar(10)

    )

    Declare @Table2 table

    (

    ID int

    , maturinty varchar(10)

    , gender varchar(10)

    , [type] varchar(10)

    )

    insert into @Table1 (ID, Age, gender)

    select 1, 18, 'Male' union all

    select 2, 13, 'Female'

    insert into @Table2 (ID, maturinty, gender, [type])

    select 1, 'Adult', 'Male','Type1' union all

    select 2, 'Child', 'Female','Type2'

    select *

    from @Table1

    select *

    from @Table2

    is this your data looks like ?

  • it is correct but while getting the data from data base according to the id from the first table if the age is less than 18 we should get child list from the second table.

    here we should compare the age whether it is above 18 or below 18 and should get the data

  • ashalatha.cse76 (4/16/2014)


    it is correct but while getting the data from data base according to the id from the first table if the age is less than 18 we should get child list from the second table.

    Share some sample data for the above statement and your desire result set.

  • table 1@sampledata

    id=1,age=18,gender=male

    table2@sample data

    id=1,maturnity=child,gender=male

    id=2,maturnity=adult,gender=female

    id=2,maturnity=child,gender=female

    id=2,maturnity=adult,gender=male

    this is the sample data

    while getting the data we will compare

    where table2.gender=table1.gender

    and table1.id=1

    in the same way i should compare age also

  • Changed the column Name from 'maturnity' to 'maturity'.

    Declare @Table1 table

    (

    ID int

    , Age int

    , gender varchar(10)

    )

    Declare @Table2 table

    (

    ID int

    , maturity varchar(10)

    , gender varchar(10)

    )

    insert into @Table1 (ID, Age, gender)

    select 1, 18, 'Male' union all

    select 2, 13, 'Female'

    insert into @Table2 (ID, maturity, gender)

    select id=1,maturity='child',gender='male' union all

    select id=2,maturity='adult',gender='female' union all

    select id=2,maturity='child',gender='female' union all

    select id=2,maturity='adult',gender='male'

    Select *

    from (

    select ID, Age, gender, case when Age < 18 then 'child' else 'adult' end as maturity

    from @Table1

    ) table1

    join @Table2 table2 on table2.gender = table1.gender

    and table2.maturity = table1.maturity

    and table1.id = 1

    hope it helps

  • it is displaying as zero records

  • ashalatha.cse76 (4/16/2014)


    it is displaying as zero records

    i have tested this script before sharing. It should return 1 row.

    Following is the result set

    ID Age gender maturity ID maturity gender

    ----------- ----------- ---------- -------- ----------- ---------- ----------

    1 18 Male adult 2 adult male

    try to copy the complete script and paste it on sql server Analyser

  • adding the table for time column i want only day hour and minutes how to declare that in sql table.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic. Login to reply