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
275.3k
How to rewrite sql query after where condition with another query ?
May 15 2021 6:20 PM
I work on sql server I need to rewrite statement after where statement so how to rewrite
I don't understand what is writing after where
so can you help me how to write it alternative
select
top
1 *
FROM
dbo.GlobalPartNumberPortions Po
WITH
(NOLOCK)
INNER
JOIN
dbo.GlobalPartNumber GOl
WITH
(NOLOCK)
ON
GOl.GlobalPnId = Po.GlobalPnId
AND
Po.GroupId = 1
INNER
JOIN
Parts.Nop_PartsFamily pf
WITH
(NOLOCK)
ON
GOl.FamilyId = pf.PartFamilyID
INNER
JOIN
dbo.GlobalPartNumberPortions Po2
WITH
(NOLOCK)
ON
GOl.GlobalPnId = Po2.GlobalPnId
AND
Po2.GroupId = 2
WHERE
@PartNumber
LIKE
CONCAT(LTRIM(RTRIM(
CASE
WHEN
Po.PortionKey=N
'Blank'
THEN
''
WHEN
CHARINDEX(
'['
, PO.PortionKey) >0
then
replace
(PO.PortionKey,N
'['
,N
'[['
)
ELSE
Po.PortionKey
END
))
,LTRIM(RTRIM(
CASE
WHEN
Po2.PortionKey=N
'Blank'
THEN
''
WHEN
CHARINDEX(
'['
, PO2.PortionKey) >0
then
replace
(PO2.PortionKey,N
'['
,N
'[['
)
ELSE
Po2.PortionKey
END
))
,
'%'
)
what i need it rewrite statement
as
below :
WHERE
@PartNumber
LIKE
CONCAT(LTRIM(RTRIM(
CASE
WHEN
Po.PortionKey=N
'Blank'
THEN
''
WHEN
CHARINDEX(
'['
, PO.PortionKey) >0
then
replace
(PO.PortionKey,N
'['
,N
'[['
)
ELSE
Po.PortionKey
END
))
,LTRIM(RTRIM(
CASE
WHEN
Po2.PortionKey=N
'Blank'
THEN
''
WHEN
CHARINDEX(
'['
, PO2.PortionKey) >0
then
replace
(PO2.PortionKey,N
'['
,N
'[['
)
ELSE
Po2.PortionKey
END
))
,
'%'
)
really i don't understand what after where condition so can you help me to understand what written after where
condition
or
rewrite it with another syntax or logic ?
this actually i need to rewrite it
WHERE
@PartNumber
LIKE
CONCAT(LTRIM(RTRIM(
CASE
WHEN
Po.PortionKey=N
'Blank'
THEN
''
WHEN
CHARINDEX(
'['
, PO.PortionKey) >0
then
replace
(PO.PortionKey,N
'['
,N
'[['
)
ELSE
Po.PortionKey
END
))
,LTRIM(RTRIM(
CASE
WHEN
Po2.PortionKey=N
'Blank'
THEN
''
WHEN
CHARINDEX(
'['
, PO2.PortionKey) >0
then
replace
(PO2.PortionKey,N
'['
,N
'[['
)
ELSE
Po2.PortionKey
END
))
,
'%'
)
portion key is RXQ6R8
@PartNumber is RXQ6R8M2WSA-1020S
Reply
Answers (
1
)
Select*from emp ( I want to run this query in 20 databases?)
getdate and sql coulmn sms_date check 20 min