|
 |
asp_databases thread: Sql Server Stored Procedure
Message #1 by "Priyadarshini" <vnimesh@y...> on Mon, 20 Aug 2001 12:37:35
|
|
Hi All..
Thanx for yr support.. I need a urgent help.. can anyone
help me pls.. well.
I have two tables within a same databse in sqlserver. The
tables are named as rawfigure and realfigure. The task is, the datas in
the rawfigure table should be inserted into the realfigure table,but only
the new values. We have a id column. So each and every record in the raw
table must be checked against the realtable id, if the id is not there
then insert it into the realfigure table,if id is there just update the
realfigure values with rawfigure values...
My stored procedure is not working.. i think the total coding is wrong..
and i am new in writing stored procedure.. so pls go thru my code and
someone please help me.. u can modify my code and send the new one so that
i can use it straight away in my application... thanx in advance.
The code is:
------
CREATE PROCEDURE sp_balaproc
as
begin
declare @tid1 char(5),@tdateofjoin1 datetime
declare balacur1 scroll cursor for select * from rawfigure
declare balacur2 scroll cursor for select * from realfigure
open balacur1
fetch next from balacur1 into @tid1,@tdateofjoin1
while @@fetch_status <> -1
open balacur2
fetch next from balacur2 into @tid2,@tdateofjaoin2
if @tid1=@tid2 then
begin
insert into realfigure values (@tid1,@tdateofjoin1)
end
return
end
------------------
Regards,
P'darshini.
Message #2 by Hal Levy <hal.levy@s...> on Mon, 20 Aug 2001 12:06:17 -0400
|
|
Gahhh!
Psudeo Code follows:
SELECT * INTO database1.realfigure from database2.rawfigure where PKid
not
in (select PKid from database1.realfigure)
Hal Levy
StarMedia Network, Inc.
Intranet Development Manager
> -----Original Message-----
> From: Priyadarshini [mailto:vnimesh@y...]
> Sent: Monday, August 20, 2001 8:38 AM
> To: ASP Databases
> Subject: [asp_databases] Sql Server Stored Procedure
>
>
> Hi All..
> Thanx for yr support.. I need a urgent help..
> can anyone
> help me pls.. well.
>
> I have two tables within a same databse in
> sqlserver. The
> tables are named as rawfigure and realfigure. The task is,
> the datas in
> the rawfigure table should be inserted into the realfigure
> table,but only
> the new values. We have a id column. So each and every record
> in the raw
> table must be checked against the realtable id, if the id is
> not there
> then insert it into the realfigure table,if id is there just
> update the
> realfigure values with rawfigure values...
>
> My stored procedure is not working.. i think the total coding
> is wrong..
> and i am new in writing stored procedure.. so pls go thru my code and
> someone please help me.. u can modify my code and send the
> new one so that
> i can use it straight away in my application... thanx in advance.
>
> The code is:
>
> ------
>
> CREATE PROCEDURE sp_balaproc
> as
> begin
> declare @tid1 char(5),@tdateofjoin1 datetime
>
> declare balacur1 scroll cursor for select * from rawfigure
> declare balacur2 scroll cursor for select * from realfigure
>
> open balacur1
> fetch next from balacur1 into @tid1,@tdateofjoin1
> while @@fetch_status <> -1
> open balacur2
> fetch next from balacur2 into @tid2,@tdateofjaoin2
> if @tid1=3D@t... then
> begin
> insert into realfigure values (@tid1,@tdateofjoin1)
> end
> return
> end
> ------------------
>
> Regards,
> P'darshini.
>
|
|
 |