Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2006, 10:41 AM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default Returning the 1st row of a SELECT Sub Query

Hi All

I wonder if someone knows the answer... I have a stored proc that looks similar to the following:
Code:
Update TABLE1
Set
FIELD2 = (SELECT FIELDB FROM TABLE2 WHERE (FIELDA= @PARAM1))
WHERE (FIELD1 = @PARAM1)
The SELECT sub query runs fine when selecting a value from TABLE2 that only appears once but TABLE2 also consists of multiple instance.. it then throws an error.

I think the answer would be to be able to select the FIRST row of the SELECT query result... is this possible in SQL 2K?

Many thanks

Rit
__________________
Rit
www.designandonline.co.uk
INSPIRE | CREATE | DELIVER
 
Old February 21st, 2006, 10:46 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How about

Update TABLE1
Set
FIELD2 = (SELECT TOP 1 FIELDB FROM TABLE2 WHERE (FIELDA= @PARAM1))
WHERE (FIELD1 = @PARAM1)



How do you know that that is the value that you want? do you have duplicates or do you have different values and you don't care what you are updating it with?



“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old February 21st, 2006, 12:20 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

that works great... I have checked whether the first record is sufficient... I know what you mean though.

Many thanks

Rit





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select row in GridView WITHOUT using Select button rao965 ASP.NET 2.0 Professional 1 February 15th, 2008 10:44 AM
Query returning all records - why? Toiletbrush Infopath 1 November 21st, 2007 03:19 AM
MySQL - Returning "most popular" row whiffin SQL Language 4 November 2nd, 2004 10:04 AM
Returning Oracle SELECT query results to DataSet gp_mk ADO.NET 0 December 17th, 2003 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.