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.
| Author |
Topic |
|
joe77s
Starting Member
10 Posts |
Posted - 2002-08-30 : 00:05:49
|
| i want to write this in store proc, but it can't....create procedure zp_insert_data@newtable nvarchar(250),@oldtable nvarchar(250)asselect * into @newtable from @oldtableand it from 2 database but still in one server..eg :@newtable = database name is "GOODSDATA"@oldtable = database name is "MERCHANDATA"how if from 2 server ?does someone know, why ? |
|
|
DavidD
Yak Posting Veteran
73 Posts |
Posted - 2002-08-30 : 02:14:08
|
| Use dynamic sqlie.create proc zp_insert_data @newtable navrchar(250), @oldtable nvarchar(250)asdeclare @sql varchar(1000)set @sql = 'select * into goodsdata..' + @newtable + ' from merchandata..' + @oldtableexec(@sql)RegardsDavid |
 |
|
|
joe77s
Starting Member
10 Posts |
Posted - 2002-09-02 : 02:15:43
|
| okay this work...thanks Davidi have 2 kind of tables1. master table2.transaction tablefor master table i already use your code,and now for my transaction table....this i try with query analyzer...and always have an errorServer: Msg 137, Level 15, State 2, Line 3Must declare the variable '@fromMonth'.declare @fromMonth as datetimedeclare @duemonth as datetimedeclare @strsql varchar(1000)declare @cmd varchar(1000)set @frommonth = '08/02/2002'set @duemonth = '09/02/2002'set @strsql = 'from MERCHANDATA.dbo.dtcontractr where contractno in (select contractno from MERCHANDATA.dbo.dtcontracth where month(contractdate) between month(@fromMonth) and month(@duemonth) and year(contractdate) between year(@fromMonth) and year(@duemonth))'set @cmd = 'select * into GOODSDATA.dbo.dtcontractr ' + @strsqlexec(@cmd)how to solve this problem ?thanks, for your attention.....joe |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-09-02 : 08:56:51
|
| set @strsql = 'from MERCHANDATA.dbo.dtcontractr where contractno in (select contractno from MERCHANDATA.dbo.dtcontracth where month(contractdate) between month(@fromMonth) and month(@duemonth) and year(contractdate) between year(@fromMonth) and year(@duemonth))' s.b.... between ' + convert(varchar(10), month(@fromMonth)) + ' and ' convert(varchar(10), month(@duemonth)) ...The parameters are not available to the exec'd batch.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
joe77s
Starting Member
10 Posts |
Posted - 2002-09-04 : 02:40:20
|
okay.... ...it's work....this solve my problem...thanks to David and nr...joe |
 |
|
|
|
|
|