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 2005 Forums
 Transact-SQL (2005)
 Help on my dynamic query

Author  Topic 

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-20 : 12:55:48
I am having this query
select * into tbl_amazon_merchant from tbl_master_merchant where merchant='Amazon.com' and updated_date=getdate()

this works nicely...

But my need is I am going to create this query using dynamic table creation as like this ..

SET @sql ='select * into tbl_'+@Ch_BoxList+'_merchant from tbl_master_merchant where Merchant =' +@Ch_BoxList+ ' and updated_date=getdate()'
EXEC (@sql)

When executing this query i received this error ..

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Amazon.com" could not be bound.
Pls help me tnx in advance....

Sachin.Nand

2937 Posts

Posted - 2010-09-20 : 13:02:31
quote:
Originally posted by jafrywilson

I am having this query
select * into tbl_amazon_merchant from tbl_master_merchant where merchant='Amazon.com' and updated_date=getdate()

this works nicely...

But my need is I am going to create this query using dynamic table creation as like this ..

SET @sql ='select * into tbl_'+@Ch_BoxList+'_merchant from tbl_master_merchant where Merchant =' +@Ch_BoxList+ ' and updated_date=getdate()'
EXEC (@sql)

When executing this query i received this error ..

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Amazon.com" could not be bound.
Pls help me tnx in advance....




Can you find something fishy in the above red part?

PBUH

Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-20 : 13:08:43
Hey Sachin.Nand that is no probs...tbl_Amazon.com_merchant will be created instead of tbl_amazon_merchant ...
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-20 : 13:11:58
When i execute the first query i didn't get error... But executing(by passing Amazon.com for @Ch_BoxList) the second query i got error
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-09-20 : 13:22:24
What happens if you assign @Ch_BoxList with Amazon instead of Amazon.com ?

PBUH

Go to Top of Page

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2010-09-20 : 13:23:39
quote:

SET @sql ='select * into tbl_'+@Ch_BoxList+'_merchant from tbl_master_merchant where Merchant =' +@Ch_BoxList+ ' and updated_date=getdate()'
EXEC (@sql)



Miss single quote.

Try this ...

SET @sql ='select * into tbl_'+@Ch_BoxList+'_merchant from tbl_master_merchant where Merchant =''' +@Ch_BoxList+ ''' and updated_date=getdate()'
EXEC (@sql)
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-09-20 : 13:27:51
quote:
Hey Sachin.Nand that is no probs...tbl_Amazon.com_merchant will be created instead of tbl_amazon_merchant ...


if this table tbl_Amazon.com_merchant gets created, it will live in the tbl_Amazon schema and be called com_merchant. Is this what you intend?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-20 : 13:46:38
quote:
Originally posted by jimf

quote:
Hey Sachin.Nand that is no probs...tbl_Amazon.com_merchant will be created instead of tbl_amazon_merchant ...


if this table tbl_Amazon.com_merchant gets created, it will live in the tbl_Amazon schema and be called com_merchant. Is this what you intend?

Jim

Everyday I learn something that somebody else already knew



Ya ..I received this error ..What can i do now..
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-20 : 14:46:44
rethink what you are doing?

Is this table creation going to be part of OLTP?

This could a complete disaster



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx





Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-20 : 14:51:22
This is not OLTP .. It is just a small application...
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-20 : 18:11:06
Tnx for response...
Go to Top of Page
   

- Advertisement -