SQL Query question
SQL Query question
SQL Query question
SQL Query question
SQL Query question
SQL Query question SQL Query question SQL Query question SQL Query question SQL Query question SQL Query question SQL Query question SQL Query question
SQL Query question SQL Query question
SQL Query question
Go Back  Xtreme Visual Basic Talk > > > SQL Query question


Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2003, 10:42 AM
VeRiTo's Avatar
VeRiTo VeRiTo is offline
Contributor
 
Join Date: Nov 2003
Location: Buenos Aires
Posts: 614
Question SQL Query question


Hi, I have a question.
This example is similar to a table i created:

[PKCode1] numeric
[PKCode2] numeric
[Description] varchar(100)

The fields that begin with PK are Table's primary key.
Well, i want to build a Query with a SELECT clause that brings me just 1 field for each PKCode1 and all descriptions for that one in just one tuple.
Example


[PKCode1] [PKCode2] [Description]
1 1 'desc 1.1'
1 2 'desc 1.2'
1 3 'desc 1.3'
2 1 'desc 2.1'
2 2 'desc 2.2'

and i want as a result:

[PKCode1] [Description]
1 'desc 1.1desc 1.2desc 1.3'
1 'desc 2.1desc 21.2'

is that possible?
__________________
.:.VeRiTo.:.
Reply With Quote
  #2  
Old 12-17-2003, 11:54 AM
Flyguy's Avatar
FlyguySQL Query question Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,162
Default

Why have these to be returned in one field?
Why not just select them sorted by the first primary key?
Reply With Quote
  #3  
Old 12-17-2003, 11:58 AM
VeRiTo's Avatar
VeRiTo VeRiTo is offline
Contributor
 
Join Date: Nov 2003
Location: Buenos Aires
Posts: 614
Default

The thing is I need to insert that description in another table in just one field, so i didnt want to use a cursor to do this!
__________________
.:.VeRiTo.:.
Reply With Quote
  #4  
Old 12-17-2003, 12:23 PM
reboot's Avatar
rebootSQL Query question reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

I'm afraid you have no choice.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #5  
Old 12-17-2003, 12:31 PM
VeRiTo's Avatar
VeRiTo VeRiTo is offline
Contributor
 
Join Date: Nov 2003
Location: Buenos Aires
Posts: 614
Default

oh, what a pitty. my problem is that i already have a cursor in my query and while i am looping through it i have to do that i explained before:
Code:
SET NOCOUNT ON

DECLARE MiCursorArt CURSOR READ_ONLY FOR 
	SELECT
		PKField1, 
		Field2, 
	FROM Table1;

DECLARE 
	@PKField1 numeric, 
	@Field2 numeric,
	@BigDescription varchar(255)

OPEN MiCursorArt

WHILE 1 = 1
BEGIN
	FETCH NEXT FROM MiCursorArt INTO
	@PKField1 , 
	@Field2 

	IF @@FETCH_STATUS <> 0 BREAK 

	IF @PKField1 <> -1
	BEGIN
 		--HERE IS WHERE I HAVE TO GET THE WHOLE DESCRIPTION (@BigDescription) IN JUST ONE FIELD
		
		INSERT INTO Table3 ...
		values (...,@BigDescription)
		
	END
END

CLOSE MiCursorArt
DEALLOCATE MiCursorArt
GO
SET NOCOUNT OFF
__________________
.:.VeRiTo.:.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQl query question in VB Ekta Database and Reporting 4 09-26-2003 01:58 PM
SQL query question davencharleston Database and Reporting 1 07-14-2003 07:16 AM
Problem with writing Twice Renidrag Web Programming 20 11-07-2002 02:52 PM
Probably a common sql query question CodeWarrior Database and Reporting 2 09-25-2002 09:09 PM
Creating Access Databases TomGuy Database and Reporting 8 07-10-2002 10:56 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
SQL Query question
SQL Query question
SQL Query question SQL Query question
SQL Query question
SQL Query question
SQL Query question SQL Query question SQL Query question SQL Query question SQL Query question SQL Query question SQL Query question
SQL Query question
SQL Query question
 
SQL Query question
SQL Query question
 
-->