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)
 Need help -- Im stuck

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2010-03-03 : 22:58:15
My table as follow,
CREATE TABLE [dbo].[tPickPointH](
[idx] [smallint] IDENTITY(1,1) NOT NULL,
[tcoutcd] [varchar](20) NOT NULL,
CONSTRAINT [PK_tPickPointH] PRIMARY KEY CLUSTERED
(
[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [tPickPointH01] UNIQUE NONCLUSTERED
(
[tcoutcd] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[tPickPointD](
[idx] [smallint] IDENTITY(1,1) NOT NULL,
[tpphidx] [smallint] NOT NULL,
[desn] [varchar](50) NOT NULL,
CONSTRAINT [PK_tPickPointD] PRIMARY KEY CLUSTERED
(
[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [tPickPointD01] UNIQUE NONCLUSTERED
(
[tpphidx] ASC,
[desn] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[tPickPointD] WITH CHECK ADD CONSTRAINT [FK_tPickPointD_tpphidx] FOREIGN KEY([tpphidx])
REFERENCES [dbo].[tPickPointH] ([idx])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[tPickPointD] CHECK CONSTRAINT [FK_tPickPointD_tpphidx]



My insert statement as follow,
declare @idx int
declare @cout varchar(20)
set @cout='iph'
declare @data xml
set @data='<data>
<pickpoints><pickpoint>gopeng</pickpoint></pickpoints>
<pickpoints><pickpoint>slim river</pickpoint></pickpoints>
</data>'
insert into dbo.tPickPointH(tcoutcd) values(@cout);
set @idx=scope_identity();
insert into dbo.tPickPointD
(tpphidx,desn)
select @idx,a.b.value('pickpoint[1]','varchar(50)')
from @data.nodes('/data/pickpoints') a(b);


So the resultset as follow,
tPickPointH
idx | tcoutcd
----------------------
1 iph
/*idx is identity(1,1)*/

tPickPointD
idx | tpphidx | desn
------------------------
1 1 gopeng
2 1 slim river


Let's say, my data as follow,

declare @idx int
set @idx=1
declare @cout varchar(20)
set @cout='iph'
declare @data xml
set @data='<data>
<pickpoints><pickpoint>gopeng</pickpoint></pickpoints>
<pickpoints><pickpoint>sungai rokam</pickpoint></pickpoints>
<pickpoints><pickpoint>sungkai</pickpoint></pickpoints>
</data>'
update tPickPointH set tcoutcd=@cout
where idx=@idx;
...
...


How my update statement at tPickPointH look like?

Really need help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-04 : 01:44:54
Didnt you get what i suggested yesterday? You need to have some kind of unique valued node inside xml to update each rows correctly. just relating by tpphidx alone will match multiple records

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

Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2010-03-04 : 05:00:09
quote:
Originally posted by visakh16

Didnt you get what i suggested yesterday? You need to have some kind of unique valued node inside xml to update each rows correctly. just relating by tpphidx alone will match multiple records

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





I'm thinking, i'm
1. not gonna to insert the record already in the tPickPointH.
2. gonna to delete the record not in the XML data

Now, my table and rows as follow
tPickPointD
idx | tpphidx | desn
------------------------
1 1 gopeng
2 1 slim river
/*we call this table as t1*/

my XML data after query will be as follow,
tpphidx | desn
------------------------
1 gopeng
1 sungai rokam
1 sungkai
/*we call this table as t2*/

I want to query between t2 and t1. this query will return as follow

1 sungai rokam
1 sungkai
/*this value, i'm gonna to insert into tPickPointD*/


and return as follow
1 slim river
/*this value, i'm gonna to delete from tPickPointD*/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-04 : 08:40:39
you need a column in your xml data to identify each value . if it corresponds to id value in second table, that would be great

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

Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2010-03-04 : 12:17:37
ok sir. your guide is my inspiration
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-04 : 12:19:12
welcome

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

Go to Top of Page
   

- Advertisement -