TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
277.8k
How to add codevalueto when codevaluefrom equal codevalue #t
Apr 9 2020 8:27 PM
problem
How to insert CodeValueTo on Table TradeCode where codevaluefrom equal to codevalue on table tradecode and not exist on Tradecode table ?
I need to insert CodeValueTo into temp table #tradecode where CodeValueFrom exist on temp table #tradecode
I work on SQL server 2012 and below is my sample data
create
table
#MappingCodeValue
(
id
int
identity (1,1),
CodeTypeFrom nvarchar(50),
CodeValueFrom nvarchar(50),
CodeTypeTo nvarchar(50),
CodeValueTo nvarchar(50)
)
INSERT
INTO
#MappingCodeValue
(CodeTypeFrom,CodeValueFrom,CodeTypeTo,CodeValueTo)
VALUES
(
'ECCS-US'
,
'AB123-US'
,
'ECCS-URB'
,
'AB123-URB'
),
(
'ECCS-US'
,
'AB555-US'
,
'ECCS-URB'
,
'AB555-URB'
),
(
'ECCS-US'
,
'AB666-US'
,
'ECCS-URB'
,
'AB666-URB'
),
(
'ECCS-US'
,
'AB756-US'
,
'ECCS-URB'
,
'AB778-URB'
)
CREATE
TABLE
#TradeCode
(
TradeCodeId
int
identity(1,1),
PartId
int
,
Partlevel
int
,
CodeType nvarchar(50),
CodeValue nvarchar(50)
)
insert
into
#TradeCode(PartId,Partlevel,CodeType,CodeValue)
VALUES
(1222,1,
'ECCS-US'
,
'AB123-US'
),
(1255,1,
'ECCS-US'
,
'AB555-US'
),
(1444,1,
'ECCS-US'
,
'AB666-US'
),
(1931,1,
'ECCS-US'
,
'AB756-US'
)
Expected data inserted
to
#tradeCode
temp
table
as
below :
(1222,1,
'ECCS-US'
,
'AB123-URB'
),
(1255,1,
'ECCS-US'
,
'AB555-URB'
),
(1444,1,
'ECCS-US'
,
'AB666-URB'
),
(1931,1,
'ECCS-US'
,
'AB778-URB'
)
I check if value of codevaluefrom on temp table #mappingcodevalue exist on temp table #tradecode field codevalue
then get equal value from codevalueTo then add it to temp table #tradecode with code type
to summarize what i need is to check #tradecode temp table field codevalue if it have same value on codevaluefrom on temp table
#mappingcodevalue then get codevalueto and add it as new row with equation value codevalueto in case of not exist on table #tradecode.
Reply
Answers (
1
)
xml column to SQL table
If record exist update partlevel from 1 to 0?