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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Getting Next value

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-03 : 08:29:19
VJ GP writes "Hi All,

I have question, i want a query for this. For example.

Below is the table name x.

Col1 col2 col3 col4
---- --- ---- ----
J3999 01 xxxxx xxxx
J3999 02 xxxxx xxxx
J3999 03 xxxxx xxxx

I want to write a query by passing the value to col1 say J3999. I want to get the output as

col2
----
02

I want to know how to write a query.

Any help will be highly appreciated..

Thanks and Regards,
VJ "

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-09-03 : 08:55:52
NEXT implies...AFTER something....AFTER WHAT???
IN SQL Terms....this will mean using the ORDER BY clause somewhere...BECAUSE only by using this clause can you GUARANTEE the ORDER of the input data...(when processed by your query)...and thus only then will the AFTER come into play.


Search here for WHAT'S AFTER TOP.....you will learn something useful from the discussions/articles on same.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-04 : 20:15:16
well supposing that you do sort on col2:

select top 1 t.col2
from (select top 2 col2 from MyTable where col2='J3999' order by col2) t
order by col2 desc

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

Mishka
Starting Member

3 Posts

Posted - 2004-09-04 : 20:24:30
I think there may be a typo in your reply Spirit. I only mention this so as to not confuse VJ.

select top 1 t.col2
from (select top 2 col2 from MyTable where col1='J3999' order by col2) t
order by col2 desc

;)

Let me know if I missed something by rushing through this!

Mishka
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-04 : 20:30:08
yeah you're right. my bad...
happens to anyone.

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

Mishka
Starting Member

3 Posts

Posted - 2004-09-04 : 20:30:59
Dont "I" know it! LOL!
Go to Top of Page
   

- Advertisement -