My database developer gave me a SQL query and it runs successfully in SSMS.
USE testdb
DECLARE @Pipeline TABLE
(
pipeline VARCHAR(4000),
unitcode VARCHAR(4000),
designareanumber VARCHAR(4000),
nameofnote VARCHAR(4000)
)
INSERT INTO @Pipeline
SELECT pipeline,
unitcode,
designareanumber,
nameofnote
FROM (SELECT pp.oid AS OID,
nmpp.itemname AS ItemName,
nmpl.itemname AS Pipeline,
tn.trainnumber AS TrainNumber,
uc.unitcode AS UnitCode,
FROM jrtepipepart pp
JOIN jnameditem nmpp
ON pp.oid = nmpp.oid
JOIN xcontainsnote xcn
ON pp.oid = xcn.oidorigin
WHERE gn.text <> ''
AND ( nmpps.itemname = 'Piping_New'
OR nmpps.itemname = 'Piping_Modified/Tie_In' )
--where gn.Text like '%000002A_TP08' AND (nmpps.ItemName = 'Piping_New' OR nmpps.ItemName = 'Piping_Modified/Tie_In')
UNION ALL
SELECT hs.oid AS OID,
nmhs.itemname AS ItemName,
nmpl.itemname AS Pipeline,
tn.trainnumber AS TrainNumber,
uc.unitcode AS UnitCode,
FROM jhgrsupport hs
JOIN jnameditem nmhs
ON hs.oid = nmhs.oid
WHERE gn.text <> ''
AND ( nmpps.itemname = 'Piping_New'
OR nmpps.itemname = 'Piping_Modified/Tie_In' ))A
SELECT pipeline,
unitcode,
designareanumber,
( Stuff((SELECT Cast('; ' + nameofnote AS VARCHAR(max))
FROM @Pipeline p2
WHERE ( p2.pipeline = p1.pipeline
AND p2.unitcode = p1.unitcode
AND p2.designareanumber = p1.designareanumber
AND nameofnote NOT IN ( 'Note 1', '' ) )
FOR xml path ('')), 1, 2, '') ) AS NameOfNote
FROM @Pipeline p1
WHERE nameofnote NOT IN ( 'Note 1', '' )
GROUP BY pipeline,
unitcode,
designareanumber
When I run above query in OleDbDataAdapter it return 0 rows. I have tried adding SET NOCOUNT ON
at start of the query but not working. I have increased set-timeout property.
Removed USE testdb
, added SET NOCOUNT ON
and added database name before table names resolved this issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.