MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 31st, 2003, 03:06 PM
jura jura is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 jura User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Design problem

Hi!
I have one, sort of theoretical, question.

Is it possible to create database i.e. like this:

3 tables: A, B, C

table A table B table C
-------------- ------------- -------------
id value id value id value
-------------- ------------- -------------
5 val1 5 val2 5 val3
5 val4 5 val5

and to extract data somehow with one sql query
to get result like this:

5 val1 val2 val3 val4 val5

in one record?

Thanks for any ideas

Reply With Quote
  #2  
Old November 14th, 2003, 10:58 AM
smackmeister smackmeister is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 21 smackmeister User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You would have to do a cursor to add them all together...

declare @id int,
@test varchar(1000),
@sql varchar(4000)

set @id = 5

declare test cursor
for select (value) from tblA where id = @id

open test
fetch next from test into @test

while @@fetch_status = 0
begin

set @sql = @sql + @test + ' '

fetch next from test into @test
end

close test
deallocate test



declare test cursor
for select (value) from tblB where id = @id

open test
fetch next from test into @test

while @@fetch_status = 0
begin

set @sql = @sql + @test + ' '

fetch next from test into @test
end

close test
deallocate test


declare test cursor
for select (value) from tblC where id = @id

open test
fetch next from test into @test

while @@fetch_status = 0
begin

set @sql = @sql + @test + ' '

fetch next from test into @test
end

close test
deallocate test


select @id + ' ' + @sql

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Design problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway