Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Compare both and round to nearest to admin value

Author  Topic 

rameshduraikannu
Starting Member

10 Posts

Posted - 2009-11-23 : 08:10:32
[code]

hai to all

I have two tables ('admin' and 'user'). These tables
contain among others fields as below
.
admin(table name)

grade
240
270
3000
user(table name)

Grade value
246
273
301


Compare both(240 admin value) and (246 user value) round to nearest to admin value(240)



I would like a query that finds the grade (from the admin
table) compares it to ' Grade value ' (from user) and returns
the Grade value

[/code].



[url]http://www.sqlservercentral.com/Forums/Attachment4582.aspx[/url]
rameshduraikannu


[code]
Create table #admin1 (grade int, a_height int,a_width int)
Create table #user1 (grade int, u_heigth int,u_width int)


INSERT INTO #admin1 VALUES (2176,200,240)
INSERT INTO #admin1 VALUES(2176,260,300)
INSERT INTO #admin1 VALUES(2716,260,360)

INSERT INTO #user1 VALUES(2176,198,210 )
INSERT INTO #user1 VALUES(2176,250,300)
INSERT INTO #user1 VALUES(2716,250,350)

select * from #user1
select * from #admin1
[code]

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-23 : 09:09:20
are you using sql 2005?
Go to Top of Page

rameshduraikannu
Starting Member

10 Posts

Posted - 2009-11-23 : 22:31:54
quote:
Originally posted by visakh16

are you using sql 2005?




quote:
i am using sqlserver 2008


rameshduraikannu
Go to Top of Page

kbhere
Yak Posting Veteran

58 Posts

Posted - 2009-11-24 : 02:54:46
Is there any relation between these 2 tables??
If so, let me know..

Balaji.K
Go to Top of Page

rameshduraikannu
Starting Member

10 Posts

Posted - 2009-11-24 : 04:49:37
quote:
Originally posted by kbhere

Is there any relation between these 2 tables??
If so, let me know..

Balaji.K




quote:
hai balaji i add the sample code this is my table structure.
the relation is grade


INSERT INTO #admin1 VALUES (2176,200,240)
INSERT INTO #admin1 VALUES(2176,260,300)
INSERT INTO #admin1 VALUES(2716,260,360)

INSERT INTO #user1 VALUES(2176,198,210 )
INSERT INTO #user1 VALUES(2176,250,300)
INSERT INTO #user1 VALUES(2716,250,350)

select * from #user1
select * from #admin1





rameshduraikannu
Go to Top of Page
   

- Advertisement -