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
 save table

Author  Topic 

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-08-24 : 07:47:56
i joined 2 tables using join query ... Now i want to use the joined table ..What can i do

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-24 : 07:51:19
what do you mean by joined table? are you asking about using joined query as a new table? if yes, do like

select columns...
from
(
your join query
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-08-24 : 08:00:49
Table 1 join table 2--->Result

how to store or use result for next query
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-24 : 08:03:18
You can put them into a temp table via SELECT * INTO #Temp, or you can use the query in-line via a derived table.

Here's an example of a derived table:
select * from (select column1, column2 from table1) dt
where ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-08-24 : 08:09:39
Table 1 join table 2--->X

I need to use x as input ... when using join query a dynamic table generated i need that table sir...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-24 : 08:19:14
Please see my previous post.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-24 : 08:26:14
quote:
Originally posted by tkizer

Please see my previous post.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Seems you are on 24/7 support today
Still problem at your project?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-08-24 : 08:27:50
i received this error

Msg 263, Level 16, State 1, Line 14
Must specify table to select from.
Msg 1038, Level 15, State 5, Line 14
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-24 : 08:28:21
quote:
Originally posted by madhivanan

quote:
Originally posted by tkizer

Please see my previous post.


Seems you are on 24/7 support today
Still problem at your project?



Got paged at 12:30am, was on the phone until about 1:30am. Then got paged again at 3:30am and am still on the phone (it's 5:30am here). Not sure when I get to go back to sleep.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-24 : 08:29:10
quote:
Originally posted by jafrywilson

i received this error

Msg 263, Level 16, State 1, Line 14
Must specify table to select from.
Msg 1038, Level 15, State 5, Line 14
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.




You'll need to put aliases on the columns that are using aggregates or functions.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-24 : 08:31:34
quote:
Originally posted by jafrywilson

i received this error

Msg 263, Level 16, State 1, Line 14
Must specify table to select from.
Msg 1038, Level 15, State 5, Line 14
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.



Post the full code you used. I think you can very well make use of derived table than temporary table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-24 : 08:36:53
quote:
Originally posted by tkizer

quote:
Originally posted by madhivanan

quote:
Originally posted by tkizer

Please see my previous post.


Seems you are on 24/7 support today
Still problem at your project?



Got paged at 12:30am, was on the phone until about 1:30am. Then got paged again at 3:30am and am still on the phone (it's 5:30am here). Not sure when I get to go back to sleep.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Ok. Let it be solved soon

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-08-24 : 08:36:57
select tbl_product.MPN_SKU,tbl_product.Product_Name,tbl_merchant.Price,tbl_merchant.Merchant from tbl_product INNER JOIN tbl_merchant on tbl_product.mobid=tbl_merchant.mobid



select mobid,
max(case when seq=1 then merchant else null end) as min_merchant,
max(case when seq=1 then price else null end) as min_price,
max(case when bseq=1 then merchant else null end) as max_merchant,
max(case when bseq=1 then price else null end) as max_price
from
(
select row_number() over (partition by mobid order by price) as seq,row_number() over (partition by mobid order by price desc) as bseq,mobid, merchant,price
from tbl_merchant
)t
where seq=1
or bseq=1
group by mobid

i need these two answers in a single table
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-24 : 08:42:29
Try this

select t1.*,t2.Product_Name from
(
select mobid,
max(case when seq=1 then merchant else null end) as min_merchant,
max(case when seq=1 then price else null end) as min_price,
max(case when bseq=1 then merchant else null end) as max_merchant,
max(case when bseq=1 then price else null end) as max_price
from
(
select row_number() over (partition by mobid order by price) as seq,row_number() over (partition by mobid order by price desc) as bseq,mobid, merchant,price
from tbl_merchant
)t
where seq=1
or bseq=1
group by mobid
) as t1 INNER JOIN tbl_product as t2 on t2.mobid=t1.mobid


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-08-24 : 08:46:31
thank u so much... Its working.........
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-08-24 : 08:48:46
thank u tkizer..for your support
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-24 : 08:50:30
quote:
Originally posted by jafrywilson

thank u so much... Its working.........


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-25 : 07:58:30
See this topic for continuation http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=149262


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -