Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3433 lines
82 KiB

  1. -- Script: uddi.v2.businessEntity.sql
  2. -- Description: Stored procedures associated with a businessEntity object.
  3. -- Note: This file is best viewed and edited with a tab width of 2.
  4. -- =============================================
  5. -- Section: Get stored procedures
  6. -- =============================================
  7. -- =============================================
  8. -- Name: net_businessEntity_get
  9. -- =============================================
  10. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_get' and type = 'P')
  11. DROP PROCEDURE net_businessEntity_get
  12. GO
  13. CREATE PROCEDURE net_businessEntity_get
  14. @businessKey uniqueidentifier,
  15. @operatorName nvarchar(450) OUTPUT,
  16. @authorizedName nvarchar(4000) OUTPUT
  17. WITH ENCRYPTION
  18. AS
  19. BEGIN
  20. DECLARE
  21. @error int,
  22. @context nvarchar(4000)
  23. SELECT
  24. @operatorName = dbo.publisherOperatorName([publisherID]),
  25. @authorizedName = ISNULL([authorizedName],dbo.publisherName([publisherID]))
  26. FROM
  27. [UDC_businessEntities]
  28. WHERE
  29. [businessKey] = @businessKey
  30. IF @@ROWCOUNT = 0
  31. BEGIN
  32. SET @error = 60210
  33. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  34. GOTO errorLabel
  35. END
  36. RETURN 0
  37. errorLabel:
  38. RAISERROR (@error, 16, 1, @context)
  39. RETURN 1
  40. END -- net_businessEntity_get
  41. GO
  42. -- =============================================
  43. -- Name: net_businessEntity_get_batch
  44. -- =============================================
  45. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_get_batch' and type = 'P')
  46. DROP PROCEDURE net_businessEntity_get_batch
  47. GO
  48. CREATE PROCEDURE net_businessEntity_get_batch
  49. @businessKey uniqueidentifier,
  50. @operatorName nvarchar(450) OUTPUT,
  51. @authorizedName nvarchar(4000) OUTPUT
  52. WITH ENCRYPTION
  53. AS
  54. BEGIN
  55. DECLARE
  56. @error int,
  57. @context nvarchar(4000)
  58. SELECT
  59. @operatorName = dbo.publisherOperatorName([publisherID]),
  60. @authorizedName = ISNULL([authorizedName],dbo.publisherName([publisherID]))
  61. FROM
  62. [UDC_businessEntities]
  63. WHERE
  64. [businessKey] = @businessKey
  65. IF @@ROWCOUNT = 0
  66. BEGIN
  67. SET @error = 60210
  68. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  69. GOTO errorLabel
  70. END
  71. -- Retrieve the contained objects
  72. EXEC net_businessEntity_descriptions_get @businessKey
  73. EXEC net_businessEntity_names_get @businessKey
  74. EXEC net_businessEntity_discoveryURLs_get @businessKey
  75. EXEC net_businessEntity_contacts_get @businessKey
  76. EXEC net_businessEntity_IdentifierBag_get @businessKey
  77. EXEC net_businessEntity_CategoryBag_get @businessKey
  78. EXEC net_businessEntity_BusinessServices_get @businessKey
  79. RETURN 0
  80. errorLabel:
  81. RAISERROR (@error, 16, 1, @context)
  82. RETURN 1
  83. END -- net_businessEntity_get_batch
  84. GO
  85. -- =============================================
  86. -- Name: net_businessInfo_get_batch
  87. -- =============================================
  88. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessInfo_get_batch' and type = 'P')
  89. DROP PROCEDURE net_businessInfo_get_batch
  90. GO
  91. CREATE PROCEDURE net_businessInfo_get_batch
  92. @businessKey uniqueidentifier,
  93. @getServiceInfos bit
  94. WITH ENCRYPTION
  95. AS
  96. BEGIN
  97. -- Retrieve the contained objects needed for a BusinessInfo
  98. EXEC net_businessEntity_descriptions_get @businessKey
  99. EXEC net_businessEntity_names_get @businessKey
  100. IF @getServiceInfos = 1
  101. BEGIN
  102. EXEC net_businessEntity_BusinessServices_get @businessKey
  103. END
  104. RETURN 0
  105. END -- net_businessEntity_get_batch
  106. GO
  107. -- =============================================
  108. -- Name: net_businessEntity_names_get
  109. -- =============================================
  110. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_names_get' and type = 'P')
  111. DROP PROCEDURE net_businessEntity_names_get
  112. GO
  113. CREATE PROCEDURE net_businessEntity_names_get
  114. @businessKey uniqueidentifier
  115. WITH ENCRYPTION
  116. AS
  117. BEGIN
  118. SELECT
  119. [isoLangCode],
  120. [name]
  121. FROM
  122. [UDC_names_BE]
  123. WHERE
  124. [businessID] = dbo.businessID(@businessKey)
  125. RETURN 0
  126. END -- net_businessEntity_names_get
  127. GO
  128. -- =============================================
  129. -- Name: net_businessEntity_descriptions_get
  130. -- =============================================
  131. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_descriptions_get' and type = 'P')
  132. DROP PROCEDURE net_businessEntity_descriptions_get
  133. GO
  134. CREATE PROCEDURE net_businessEntity_descriptions_get
  135. @businessKey uniqueidentifier
  136. WITH ENCRYPTION
  137. AS
  138. BEGIN
  139. SELECT
  140. [isoLangCode],
  141. [description]
  142. FROM
  143. [UDC_businessDesc]
  144. WHERE
  145. [businessID] = dbo.businessID(@businessKey)
  146. RETURN 0
  147. END -- net_businessEntity_descriptions_get
  148. GO
  149. -- =============================================
  150. -- Name: net_businessEntity_discoveryURLs_get
  151. -- =============================================
  152. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_discoveryURLs_get' and type = 'P')
  153. DROP PROCEDURE net_businessEntity_discoveryURLs_get
  154. GO
  155. CREATE PROCEDURE net_businessEntity_discoveryURLs_get
  156. @businessKey uniqueidentifier
  157. WITH ENCRYPTION
  158. AS
  159. BEGIN
  160. SELECT
  161. [useType],
  162. [discoveryURL]
  163. FROM
  164. [UDC_discoveryURLs]
  165. WHERE
  166. [businessID] = dbo.businessID(@businessKey)
  167. RETURN 0
  168. END -- net_businessEntity_discoveryURLs_get
  169. GO
  170. -- =============================================
  171. -- Name: net_businessEntity_businessServices_get
  172. -- =============================================
  173. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_businessServices_get' and type = 'P')
  174. DROP PROCEDURE net_businessEntity_businessServices_get
  175. GO
  176. CREATE PROCEDURE net_businessEntity_businessServices_get
  177. @businessKey uniqueidentifier
  178. WITH ENCRYPTION
  179. AS
  180. BEGIN
  181. DECLARE
  182. @error int,
  183. @context nvarchar(4000),
  184. @maxBigInt bigint
  185. SET @maxBigInt = 9223372036854775807
  186. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @businessKey)
  187. BEGIN
  188. SET @error = 60210 -- E_invalidKeyPassed
  189. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  190. GOTO errorLabel
  191. END
  192. SELECT
  193. [serviceKey],
  194. NULL AS [businessKey],
  195. [lastChange],
  196. [serviceID]
  197. FROM
  198. [UDC_businessServices]
  199. WHERE
  200. ([businessID] = dbo.businessID(@businessKey))
  201. UNION
  202. SELECT
  203. SP.[serviceKey],
  204. SP.[businessKey2], -- businessKey of true parent business of a projected service
  205. SP.[lastChange],
  206. ISNULL(BS.[serviceID],@maxBigInt)
  207. FROM
  208. [UDC_serviceProjections] SP
  209. LEFT JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  210. WHERE
  211. (SP.[businessKey] = @businessKey)
  212. ORDER BY
  213. 3 ASC, -- [lastChange]
  214. 4 ASC -- [serviceID]
  215. RETURN 0
  216. errorLabel:
  217. RAISERROR (@error, 16, 1, @context)
  218. RETURN 1
  219. END -- net_businessEntity_businessServices_get
  220. GO
  221. -- =============================================
  222. -- Name: net_businessEntity_contacts_get
  223. -- =============================================
  224. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_contacts_get' and type = 'P')
  225. DROP PROCEDURE net_businessEntity_contacts_get
  226. GO
  227. CREATE PROCEDURE net_businessEntity_contacts_get
  228. @businessKey uniqueidentifier
  229. WITH ENCRYPTION
  230. AS
  231. BEGIN
  232. SELECT
  233. [contactID],
  234. [useType],
  235. [personName]
  236. FROM
  237. [UDC_contacts]
  238. WHERE
  239. [businessID] = dbo.businessID(@businessKey)
  240. RETURN 0
  241. END -- net_businessEntity_contacts_get
  242. GO
  243. -- =============================================
  244. -- Name: net_businessEntity_contact_get_batch
  245. -- =============================================
  246. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_contact_get_batch' and type = 'P')
  247. DROP PROCEDURE net_businessEntity_contact_get_batch
  248. GO
  249. CREATE PROCEDURE net_businessEntity_contact_get_batch
  250. @contactID bigint
  251. WITH ENCRYPTION
  252. AS
  253. BEGIN
  254. -- Get all contained objects in a contact
  255. EXEC net_contact_descriptions_get @contactID
  256. EXEC net_contact_phones_get @contactID
  257. EXEC net_contact_emails_get @contactID
  258. EXEC net_contact_addresses_get @contactID
  259. END -- net_businessEntity_contact_get_batch
  260. GO
  261. -- =============================================
  262. -- Name: net_contact_descriptions_get
  263. -- =============================================
  264. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_descriptions_get' and type = 'P')
  265. DROP PROCEDURE net_contact_descriptions_get
  266. GO
  267. CREATE PROCEDURE net_contact_descriptions_get
  268. @contactID bigint
  269. WITH ENCRYPTION
  270. AS
  271. BEGIN
  272. SELECT
  273. [isoLangCode],
  274. [description]
  275. FROM
  276. [UDC_contactDesc]
  277. WHERE
  278. [contactID] = @contactID
  279. RETURN 0
  280. END -- net_contact_descriptions_get
  281. GO
  282. -- =============================================
  283. -- Name: net_businessEntity_categoryBag_get
  284. -- =============================================
  285. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_categoryBag_get' and type = 'P')
  286. DROP PROCEDURE net_businessEntity_categoryBag_get
  287. GO
  288. CREATE PROCEDURE net_businessEntity_categoryBag_get
  289. @businessKey uniqueidentifier
  290. WITH ENCRYPTION
  291. AS
  292. BEGIN
  293. SELECT
  294. [keyName],
  295. [keyValue],
  296. [tModelKey]
  297. FROM
  298. [UDC_categoryBag_BE]
  299. WHERE
  300. [businessID] = dbo.businessID(@businessKey)
  301. RETURN 0
  302. END -- net_businessEntity_categoryBag_get
  303. GO
  304. -- =============================================
  305. -- Name: net_businessEntity_identifierBag_get
  306. -- =============================================
  307. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_identifierBag_get' and type = 'P')
  308. DROP PROCEDURE net_businessEntity_identifierBag_get
  309. GO
  310. CREATE PROCEDURE net_businessEntity_identifierBag_get
  311. @businessKey uniqueidentifier
  312. WITH ENCRYPTION
  313. AS
  314. BEGIN
  315. SELECT
  316. [keyName],
  317. [keyValue],
  318. [tModelKey]
  319. FROM
  320. [UDC_identifierBag_BE]
  321. WHERE
  322. [businessID] = dbo.businessID(@businessKey)
  323. RETURN 0
  324. END -- net_businessEntity_identifierBag_get
  325. GO
  326. -- =============================================
  327. -- Name: net_contact_emails_get
  328. -- =============================================
  329. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_emails_get' and type = 'P')
  330. DROP PROCEDURE net_contact_emails_get
  331. GO
  332. CREATE PROCEDURE net_contact_emails_get
  333. @contactID bigint
  334. WITH ENCRYPTION
  335. AS
  336. BEGIN
  337. SELECT
  338. [useType],
  339. [email]
  340. FROM
  341. [UDC_emails]
  342. WHERE
  343. [contactID] = @contactID
  344. RETURN 0
  345. END -- net_contact_emails_get
  346. GO
  347. -- =============================================
  348. -- Name: net_contact_phones_get
  349. -- =============================================
  350. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_phones_get' and type = 'P')
  351. DROP PROCEDURE net_contact_phones_get
  352. GO
  353. CREATE PROCEDURE net_contact_phones_get
  354. @contactID bigint
  355. WITH ENCRYPTION
  356. AS
  357. BEGIN
  358. SELECT
  359. [useType],
  360. [phone]
  361. FROM
  362. [UDC_phones]
  363. WHERE
  364. [contactID] = @contactID
  365. RETURN 0
  366. END -- net_contact_phones_get
  367. GO
  368. -- =============================================
  369. -- Name: net_contact_addresses_get
  370. -- =============================================
  371. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_addresses_get' and type = 'P')
  372. DROP PROCEDURE net_contact_addresses_get
  373. GO
  374. CREATE PROCEDURE net_contact_addresses_get
  375. @contactID bigint
  376. WITH ENCRYPTION
  377. AS
  378. BEGIN
  379. SELECT
  380. [addressID],
  381. [sortCode],
  382. [useType],
  383. [tModelKey]
  384. FROM
  385. [UDC_addresses]
  386. WHERE
  387. [contactID] = @contactID
  388. RETURN 0
  389. END -- net_contact_addresses_get
  390. GO
  391. -- =============================================
  392. -- Name: net_address_addressLines_get
  393. -- =============================================
  394. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_address_addressLines_get' and type = 'P')
  395. DROP PROCEDURE net_address_addressLines_get
  396. GO
  397. CREATE PROCEDURE net_address_addressLines_get
  398. @addressID bigint
  399. WITH ENCRYPTION
  400. AS
  401. BEGIN
  402. SELECT
  403. [addressLine],
  404. [keyName],
  405. [keyValue]
  406. FROM
  407. [UDC_addressLines]
  408. WHERE
  409. [addressID] = @addressID
  410. RETURN 0
  411. END -- net_address_addressLines_get
  412. GO
  413. -- =============================================
  414. -- Section: Save stored procedures
  415. -- =============================================
  416. -- =============================================
  417. -- Name: net_businessEntity_save
  418. -- =============================================
  419. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_save' and type = 'P')
  420. DROP PROCEDURE net_businessEntity_save
  421. GO
  422. CREATE PROCEDURE net_businessEntity_save
  423. @businessKey uniqueidentifier,
  424. @PUID nvarchar(450),
  425. @generic varchar(20),
  426. @contextID uniqueidentifier,
  427. @lastChange bigint,
  428. @authorizedName nvarchar(4000) OUTPUT,
  429. @operatorName nvarchar(450) OUTPUT
  430. WITH ENCRYPTION
  431. AS
  432. BEGIN
  433. DECLARE
  434. @RC int,
  435. @error int,
  436. @context nvarchar(4000),
  437. @publisherID bigint,
  438. @isReplPublisher bit
  439. SET @RC = 0
  440. SET @publisherID = dbo.publisherID(@PUID)
  441. IF (@publisherID IS NULL)
  442. BEGIN
  443. SET @error = 60150 -- E_unknownUser
  444. SET @context = 'Invalid publisherID.'
  445. GOTO errorLabel
  446. END
  447. SET @isReplPublisher = dbo.isReplPublisher(@PUID)
  448. IF @isReplPublisher = 0
  449. SET @authorizedName = NULL
  450. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @businessKey)
  451. BEGIN
  452. DELETE [UDC_businessEntities] WHERE [businessKey] = @businessKey
  453. END
  454. ELSE
  455. BEGIN
  456. IF (@isReplPublisher = 1)
  457. BEGIN
  458. -- perform this check only for replication publishers
  459. IF (dbo.isUuidUnique(@businessKey) = 0)
  460. BEGIN
  461. SET @error = 60210 -- E_invalidKeyPassed
  462. SET @context = 'Key is not unique. businessKey = ' + dbo.UUIDSTR(@businessKey)
  463. GOTO errorLabel
  464. END
  465. END
  466. END
  467. INSERT [UDC_businessEntities](
  468. [publisherID],
  469. [generic],
  470. [authorizedName],
  471. [businessKey],
  472. [lastChange])
  473. VALUES(
  474. @publisherID,
  475. ISNULL(@generic,dbo.configValue('CurrentAPIVersion')),
  476. @authorizedName,
  477. @businessKey,
  478. @lastChange)
  479. SET @authorizedName = dbo.publisherName(@publisherID)
  480. SET @operatorName = dbo.publisherOperatorName(@publisherID)
  481. RETURN 0
  482. errorLabel:
  483. RAISERROR (@error, 16, 1, @context)
  484. RETURN 1
  485. END -- net_businessEntity_save
  486. GO
  487. -- =============================================
  488. -- Name: net_businessEntity_name_save
  489. -- =============================================
  490. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_name_save' and type = 'P')
  491. DROP PROCEDURE net_businessEntity_name_save
  492. GO
  493. CREATE PROCEDURE net_businessEntity_name_save
  494. @businessKey uniqueidentifier,
  495. @isoLangCode varchar(17) = 'en',
  496. @name nvarchar(450)
  497. WITH ENCRYPTION
  498. AS
  499. BEGIN
  500. DECLARE
  501. @RC int,
  502. @error int,
  503. @context nvarchar(4000)
  504. -- Check for valid name
  505. IF (@name IS NULL) OR (LEN(@name) = 0)
  506. BEGIN
  507. SET @error = 60500 -- E_fatalError
  508. SET @context = 'name cannot be blank.'
  509. GOTO errorLabel
  510. END
  511. INSERT [UDC_names_BE](
  512. [businessID],
  513. [isoLangCode],
  514. [name])
  515. VALUES(
  516. dbo.businessID(@businessKey),
  517. @isoLangCode,
  518. @name)
  519. RETURN 0
  520. errorLabel:
  521. RAISERROR (@error, 16, 1, @context)
  522. RETURN 1
  523. END -- net_businessEntity_name_save
  524. GO
  525. -- =============================================
  526. -- Name: net_businessEntity_description_save
  527. -- =============================================
  528. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_description_save' and type = 'P')
  529. DROP PROCEDURE net_businessEntity_description_save
  530. GO
  531. CREATE PROCEDURE net_businessEntity_description_save
  532. @businessKey uniqueidentifier,
  533. @isoLangCode varchar(17) = 'en',
  534. @description nvarchar(4000)
  535. WITH ENCRYPTION
  536. AS
  537. BEGIN
  538. INSERT [UDC_businessDesc](
  539. [businessID],
  540. [isoLangCode],
  541. [description])
  542. VALUES(
  543. dbo.businessID(@businessKey),
  544. @isoLangCode,
  545. @description)
  546. RETURN 0
  547. END -- net_businessEntity_description_save
  548. GO
  549. -- =============================================
  550. -- Name: net_businessEntity_discoveryURL_save
  551. -- =============================================
  552. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_discoveryURL_save' and type = 'P')
  553. DROP PROCEDURE net_businessEntity_discoveryURL_save
  554. GO
  555. CREATE PROCEDURE net_businessEntity_discoveryURL_save
  556. @businessKey uniqueidentifier,
  557. @useType nvarchar(4000),
  558. @discoveryURL nvarchar(4000)
  559. WITH ENCRYPTION
  560. AS
  561. BEGIN
  562. INSERT [UDC_discoveryURLs](
  563. [businessID],
  564. [useType],
  565. [discoveryURL])
  566. VALUES(
  567. dbo.businessID(@businessKey),
  568. @useType,
  569. @discoveryURL)
  570. RETURN 0
  571. END -- net_businessEntity_discoveryURL_save
  572. GO
  573. -- =============================================
  574. -- Name: net_businessEntity_categoryBag_save
  575. -- =============================================
  576. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_categoryBag_save' and type = 'P')
  577. DROP PROCEDURE net_businessEntity_categoryBag_save
  578. GO
  579. CREATE PROCEDURE net_businessEntity_categoryBag_save
  580. @businessKey uniqueidentifier,
  581. @keyName nvarchar(255),
  582. @keyValue nvarchar(255),
  583. @tModelKey uniqueidentifier
  584. WITH ENCRYPTION
  585. AS
  586. BEGIN
  587. INSERT [UDC_categoryBag_BE](
  588. [businessID],
  589. [keyName],
  590. [keyValue],
  591. [tModelKey])
  592. VALUES(
  593. dbo.businessID(@businessKey),
  594. @keyName,
  595. @keyValue,
  596. @tModelKey)
  597. RETURN 0
  598. END -- net_businessEntity_categoryBag_save
  599. GO
  600. -- =============================================
  601. -- Name: net_businessEntity_identifierBag_save
  602. -- =============================================
  603. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_identifierBag_save' and type = 'P')
  604. DROP PROCEDURE net_businessEntity_identifierBag_save
  605. GO
  606. CREATE PROCEDURE net_businessEntity_identifierBag_save
  607. @businessKey uniqueidentifier,
  608. @keyName nvarchar(255),
  609. @keyValue nvarchar(255),
  610. @tModelKey uniqueidentifier
  611. WITH ENCRYPTION
  612. AS
  613. BEGIN
  614. INSERT [UDC_identifierBag_BE](
  615. [businessID],
  616. [keyName],
  617. [keyValue],
  618. [tModelKey])
  619. VALUES(
  620. dbo.businessID(@businessKey),
  621. @keyName,
  622. @keyValue,
  623. @tModelKey)
  624. RETURN 0
  625. END -- net_businessEntity_categoryBag_save
  626. GO
  627. -- =============================================
  628. -- Name: net_businessEntity_contact_save
  629. -- =============================================
  630. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_contact_save' and type = 'P')
  631. DROP PROCEDURE net_businessEntity_contact_save
  632. GO
  633. CREATE PROCEDURE net_businessEntity_contact_save
  634. @businessKey uniqueidentifier,
  635. @useType nvarchar(4000),
  636. @personName nvarchar(4000),
  637. @contactID bigint OUTPUT
  638. WITH ENCRYPTION
  639. AS
  640. BEGIN
  641. DECLARE
  642. @error int,
  643. @context nvarchar(4000)
  644. INSERT [UDC_contacts](
  645. [businessID],
  646. [useType],
  647. [personName])
  648. VALUES(
  649. dbo.businessID(@businessKey),
  650. @useType,
  651. @personName)
  652. SET @contactID = @@IDENTITY
  653. RETURN 0
  654. errorLabel:
  655. RAISERROR (@error, 16, 1, @context)
  656. RETURN 1
  657. END -- net_businessEntity_contact_save
  658. GO
  659. -- =============================================
  660. -- Name: net_contact_description_save
  661. -- =============================================
  662. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_description_save' and type = 'P')
  663. DROP PROCEDURE net_contact_description_save
  664. GO
  665. CREATE PROCEDURE net_contact_description_save
  666. @contactID bigint,
  667. @isoLangCode varchar(17) = 'en',
  668. @description nvarchar(4000)
  669. WITH ENCRYPTION
  670. AS
  671. BEGIN
  672. INSERT [UDC_contactDesc](
  673. [contactID],
  674. [isoLangCode],
  675. [description])
  676. VALUES(
  677. @contactID,
  678. @isoLangCode,
  679. @description)
  680. RETURN 0
  681. END -- net_contact_description_save
  682. GO
  683. -- =============================================
  684. -- Name: net_contact_email_save
  685. -- =============================================
  686. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_email_save' and type = 'P')
  687. DROP PROCEDURE net_contact_email_save
  688. GO
  689. CREATE PROCEDURE net_contact_email_save
  690. @contactID bigint,
  691. @useType nvarchar(4000),
  692. @email nvarchar(4000)
  693. WITH ENCRYPTION
  694. AS
  695. BEGIN
  696. INSERT [UDC_emails](
  697. [contactID],
  698. [useType],
  699. [email])
  700. VALUES(
  701. @contactID,
  702. @useType,
  703. @email)
  704. RETURN 0
  705. END -- net_contact_email_save
  706. GO
  707. -- =============================================
  708. -- Name: net_contact_phone_save
  709. -- =============================================
  710. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_phone_save' and type = 'P')
  711. DROP PROCEDURE net_contact_phone_save
  712. GO
  713. CREATE PROCEDURE net_contact_phone_save
  714. @contactID bigint,
  715. @useType nvarchar(4000),
  716. @phone nvarchar(4000)
  717. WITH ENCRYPTION
  718. AS
  719. BEGIN
  720. INSERT [UDC_phones](
  721. [contactID],
  722. [useType],
  723. [phone])
  724. VALUES(
  725. @contactID,
  726. @useType,
  727. @phone)
  728. RETURN 0
  729. END -- net_contact_phone_save
  730. GO
  731. -- =============================================
  732. -- Name: net_contact_address_save
  733. -- =============================================
  734. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_contact_address_save' and type = 'P')
  735. DROP PROCEDURE net_contact_address_save
  736. GO
  737. CREATE PROCEDURE net_contact_address_save
  738. @contactID bigint,
  739. @sortCode nvarchar(4000),
  740. @useType nvarchar(4000),
  741. @tModelKey uniqueidentifier = NULL,
  742. @addressID bigint OUTPUT
  743. WITH ENCRYPTION
  744. AS
  745. BEGIN
  746. DECLARE
  747. @numRows int
  748. INSERT [UDC_addresses](
  749. [contactID],
  750. [sortCode],
  751. [useType],
  752. [tModelKey])
  753. VALUES(
  754. @contactID,
  755. @sortCode,
  756. @useType,
  757. @tModelKey)
  758. SET @addressID = @@IDENTITY
  759. RETURN 0
  760. END -- net_contact_address_save
  761. GO
  762. -- =============================================
  763. -- Name: net_address_addressLine_save
  764. -- =============================================
  765. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_address_addressLine_save' and type = 'P')
  766. DROP PROCEDURE net_address_addressLine_save
  767. GO
  768. CREATE PROCEDURE net_address_addressLine_save
  769. @addressID bigint,
  770. @addressLine nvarchar(4000),
  771. @keyName nvarchar(255) = NULL,
  772. @keyValue nvarchar(255) = NULL
  773. WITH ENCRYPTION
  774. AS
  775. BEGIN
  776. INSERT [UDC_addressLines](
  777. [addressID],
  778. [addressLine],
  779. [keyName],
  780. [keyValue])
  781. VALUES(
  782. @addressID,
  783. @addressLine,
  784. @keyName,
  785. @keyValue)
  786. RETURN 0
  787. END -- net_address_addressLine_save
  788. GO
  789. -- =============================================
  790. -- Section: Delete stored procedures
  791. -- =============================================
  792. -- =============================================
  793. -- Name: net_businessEntity_delete
  794. -- =============================================
  795. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_delete' and type = 'P')
  796. DROP PROCEDURE net_businessEntity_delete
  797. GO
  798. CREATE PROCEDURE net_businessEntity_delete
  799. @PUID nvarchar(450),
  800. @businessKey uniqueidentifier,
  801. @contextID uniqueidentifier
  802. WITH ENCRYPTION
  803. AS
  804. BEGIN
  805. DECLARE
  806. @RC int,
  807. @error int,
  808. @context nvarchar(4000),
  809. @operatorID bigint,
  810. @publisherID bigint
  811. SET @RC = 0
  812. --
  813. -- Validate parameters
  814. --
  815. IF @businessKey IS NULL
  816. BEGIN
  817. SET @error = 60210 -- E_invalidKey
  818. SET @context = '@businessKey is required.'
  819. GOTO errorLabel
  820. END
  821. -- Validate publisher
  822. SET @publisherID = dbo.publisherID(@PUID)
  823. IF @publisherID IS NULL
  824. BEGIN
  825. SET @error = 60150 -- E_unknownUser
  826. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  827. GOTO errorLabel
  828. END
  829. -- Validate operator
  830. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT
  831. IF @RC <> 0
  832. BEGIN
  833. SET @error = 50006 -- E_subProcFailure
  834. SET @context = ''
  835. GOTO errorLabel
  836. END
  837. -- Check to see if businessKey exists
  838. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE ([businessKey] = @businessKey))
  839. BEGIN
  840. -- businessKey exists. Make sure it belongs to current publisher
  841. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE ([businessKey] = @businessKey) AND (publisherID = @publisherID))
  842. BEGIN
  843. SET @error = 60140 -- E_userMismatch
  844. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  845. GOTO errorLabel
  846. END
  847. END
  848. ELSE
  849. BEGIN
  850. SET @error = 60210 -- E_invalidKey
  851. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  852. GOTO errorLabel
  853. END
  854. -- Delete business
  855. DELETE
  856. [UDC_businessEntities]
  857. WHERE
  858. [businessKey] = @businessKey
  859. -- Delete assertions
  860. DELETE
  861. [UDC_assertions_BE]
  862. WHERE
  863. [fromKey] = @businessKey
  864. DELETE
  865. [UDC_assertions_BE]
  866. WHERE
  867. [toKey] = @businessKey
  868. RETURN 0
  869. errorLabel:
  870. RAISERROR (@error, 16, 1, @context)
  871. RETURN 1
  872. END -- net_businessEntity_delete
  873. GO
  874. -- =============================================
  875. -- Section: Validation stored procedures
  876. -- =============================================
  877. -- =============================================
  878. -- Name: net_businessEntity_validate
  879. -- =============================================
  880. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_businessEntity_validate' AND type = 'P')
  881. DROP PROCEDURE net_businessEntity_validate
  882. GO
  883. CREATE PROCEDURE net_businessEntity_validate
  884. @PUID nvarchar(450),
  885. @businessKey uniqueidentifier,
  886. @flag int = 0
  887. WITH ENCRYPTION
  888. AS
  889. BEGIN
  890. DECLARE
  891. @RC int,
  892. @error int,
  893. @context nvarchar(4000),
  894. @operatorID bigint,
  895. @publisherID bigint,
  896. @replActive bit
  897. SET @RC = 0
  898. SET @replActive = 0
  899. IF @flag IS NULL
  900. SET @flag = 0
  901. --
  902. -- Validate parameters
  903. --
  904. IF @businessKey IS NULL
  905. BEGIN
  906. SET @error = 60210 -- E_invalidKey
  907. SET @context = '@businessKey is required.'
  908. GOTO errorLabel
  909. END
  910. -- Validate publisher
  911. SET @publisherID = dbo.publisherID(@PUID)
  912. IF @publisherID IS NULL
  913. BEGIN
  914. SET @error = 60150 -- E_unknownUser
  915. SET @context = 'PUID = ' + ISNULL(@PUID, 'NULL')
  916. GOTO errorLabel
  917. END
  918. -- Validate operator / publisher association (replication only)
  919. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT, @replActive OUTPUT
  920. IF @RC <> 0
  921. BEGIN
  922. SET @error = 50006 -- E_subProcFailure
  923. SET @context = ''
  924. GOTO errorLabel
  925. END
  926. --
  927. -- Validate businessEntity
  928. --
  929. -- Check to see if businessKey exists
  930. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE ([businessKey] = @businessKey))
  931. BEGIN
  932. -- businessKey exists. Make sure it belongs to current publisher
  933. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE ([businessKey] = @businessKey) AND (publisherID = @publisherID))
  934. BEGIN
  935. SET @error = 60140 -- E_userMismatch
  936. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  937. GOTO errorLabel
  938. END
  939. IF @replActive = 0
  940. BEGIN
  941. IF @operatorID <> dbo.currentOperatorID()
  942. BEGIN
  943. SET @error = 60130 -- E_operatorMismatch
  944. SET @context = 'Operator ' + dbo.operatorName(@operatorID) + ' is not the local operator.'
  945. GOTO errorLabel
  946. END
  947. END
  948. END
  949. ELSE
  950. BEGIN
  951. -- businessKey doesn't exist
  952. IF (@replActive = 0) AND (@flag & 0x1 <> 0x1)
  953. BEGIN
  954. -- save isn't coming from replication and pre-assigned keys flag is not set so throw an error
  955. SET @error = 60210 -- E_invalidKey
  956. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  957. GOTO errorLabel
  958. END
  959. END
  960. RETURN 0
  961. errorLabel:
  962. RAISERROR (@error, 16, 1, @context)
  963. RETURN 1
  964. END -- net_businessEntity_validate
  965. GO
  966. -- =============================================
  967. -- Section: Publisher assertions
  968. -- =============================================
  969. -- =============================================
  970. -- Name: net_businessEntity_assertions_get
  971. -- =============================================
  972. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'net_businessEntity_assertions_get' and type = 'P')
  973. DROP PROCEDURE net_businessEntity_assertions_get
  974. GO
  975. CREATE PROCEDURE net_businessEntity_assertions_get
  976. @fromKey uniqueidentifier,
  977. @toKey uniqueidentifier,
  978. @completionStatus int
  979. WITH ENCRYPTION
  980. AS
  981. BEGIN
  982. DECLARE
  983. @error int,
  984. @context nvarchar(4000)
  985. SELECT
  986. PA.[fromKey],
  987. PA.[toKey],
  988. PA.[keyName],
  989. PA.[keyValue],
  990. PA.[tModelKey]
  991. FROM
  992. [UDC_assertions_BE] PA
  993. WHERE
  994. (PA.[fromKey] = @fromKey) AND
  995. (PA.[toKey] = @toKey) AND
  996. (PA.[flag] = @completionStatus)
  997. RETURN 0
  998. errorLabel:
  999. RAISERROR (@error, 16, 1, @context)
  1000. RETURN 1
  1001. END -- net_businessEntity_assertions_get
  1002. GO
  1003. -- =============================================
  1004. -- Section: Find stored procedures
  1005. -- =============================================
  1006. -- =============================================
  1007. -- Name: net_find_businessEntity_name
  1008. -- =============================================
  1009. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_businessEntity_name' AND type = 'P')
  1010. DROP PROCEDURE net_find_businessEntity_name
  1011. GO
  1012. CREATE PROCEDURE net_find_businessEntity_name
  1013. @contextID uniqueidentifier,
  1014. @isoLangCode varchar(17) = '%',
  1015. @name nvarchar(450),
  1016. @exactNameMatch bit,
  1017. @caseSensitiveMatch bit,
  1018. @rows int OUTPUT
  1019. WITH ENCRYPTION
  1020. AS
  1021. BEGIN
  1022. -- Adds name search arguments for a find_business
  1023. DECLARE
  1024. @error int,
  1025. @context nvarchar(4000),
  1026. @contextRows int,
  1027. @wildCardSarg nvarchar(451)
  1028. DECLARE @tempKeys TABLE(
  1029. [entityKey] uniqueidentifier,
  1030. [name] nvarchar(450))
  1031. SET @contextRows = dbo.contextRows(@contextID)
  1032. IF dbo.containsWildcard(@isoLangCode) = 0
  1033. SET @isoLangCode = @isoLangCode + N'%'
  1034. --
  1035. -- Do a wildcard search (default)
  1036. --
  1037. IF (@exactNameMatch = 0)
  1038. BEGIN
  1039. SET @wildCardSarg = @name
  1040. IF dbo.containsWildcard(@name) = 0
  1041. SET @wildCardSarg = @wildCardSarg + N'%'
  1042. IF @contextRows = 0
  1043. BEGIN
  1044. INSERT INTO @tempKeys(
  1045. [entityKey],
  1046. [name])
  1047. SELECT
  1048. BE.[businessKey],
  1049. BN.[name]
  1050. FROM
  1051. [UDC_businessEntities] BE JOIN
  1052. [UDC_names_BE] BN ON BE.[businessID] = BN.[businessID]
  1053. WHERE
  1054. (BN.[name] LIKE @wildCardSarg) AND
  1055. (BN.[isoLangCode] LIKE @isoLangCode)
  1056. END
  1057. ELSE
  1058. BEGIN
  1059. INSERT INTO @tempKeys(
  1060. [entityKey],
  1061. [name])
  1062. SELECT
  1063. BE.[businessKey],
  1064. BN.[name]
  1065. FROM
  1066. [UDC_businessEntities] BE JOIN
  1067. [UDC_names_BE] BN ON BE.[businessID] = BN.[businessID]
  1068. WHERE
  1069. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1070. (BN.[name] LIKE @wildCardSarg) AND
  1071. (BN.[isoLangCode] LIKE @isoLangCode)
  1072. END
  1073. END
  1074. --
  1075. -- Do an exactNameMatch search
  1076. --
  1077. IF (@exactNameMatch = 1)
  1078. BEGIN
  1079. IF @contextRows = 0
  1080. BEGIN
  1081. INSERT INTO @tempKeys(
  1082. [entityKey],
  1083. [name])
  1084. SELECT
  1085. BE.[businessKey],
  1086. BN.[name]
  1087. FROM
  1088. [UDC_businessEntities] BE JOIN
  1089. [UDC_names_BE] BN ON BE.[businessID] = BN.[businessID]
  1090. WHERE
  1091. (BN.[name] = @name) AND
  1092. (BN.[isoLangCode] LIKE @isoLangCode)
  1093. END
  1094. ELSE
  1095. BEGIN
  1096. INSERT INTO @tempKeys(
  1097. [entityKey],
  1098. [name])
  1099. SELECT
  1100. BE.[businessKey],
  1101. BN.[name]
  1102. FROM
  1103. [UDC_businessEntities] BE JOIN
  1104. [UDC_names_BE] BN ON BE.[businessID] = BN.[businessID]
  1105. WHERE
  1106. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1107. (BN.[name] = @name) AND
  1108. (BN.[isoLangCode] LIKE @isoLangCode)
  1109. END
  1110. END
  1111. IF (@caseSensitiveMatch = 1)
  1112. DELETE
  1113. @tempKeys
  1114. WHERE
  1115. (dbo.caseSensitiveMatch(@name, [name], @exactNameMatch) = 0)
  1116. -- name search arguments are combined using a logical OR by default
  1117. INSERT [UDS_findScratch] (
  1118. [contextID],
  1119. [entityKey])
  1120. SELECT DISTINCT
  1121. @contextID,
  1122. [entityKey]
  1123. FROM
  1124. @tempKeys
  1125. WHERE
  1126. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1127. SET @rows = @@ROWCOUNT
  1128. RETURN 0
  1129. errorLabel:
  1130. RAISERROR (@error, 16, 1, @context)
  1131. RETURN 1
  1132. END -- net_find_businessEntity_name
  1133. GO
  1134. -- =============================================
  1135. -- Name: net_find_businessEntity_discoveryURL
  1136. -- =============================================
  1137. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_businessEntity_discoveryURL' AND type = 'P')
  1138. DROP PROCEDURE net_find_businessEntity_discoveryURL
  1139. GO
  1140. CREATE PROCEDURE net_find_businessEntity_discoveryURL
  1141. @contextID uniqueidentifier,
  1142. @useType nvarchar(4000),
  1143. @discoveryURL nvarchar(4000),
  1144. @rows int OUTPUT
  1145. WITH ENCRYPTION
  1146. AS
  1147. BEGIN
  1148. -- Adds discoveryURL search arguments for a find_business
  1149. DECLARE
  1150. @error int,
  1151. @context nvarchar(4000),
  1152. @contextRows int,
  1153. @defaultPattern nvarchar(4000),
  1154. @businessKeyStr char(36),
  1155. @businessKey uniqueidentifier
  1156. DECLARE @tempKeys TABLE(
  1157. [entityKey] uniqueidentifier)
  1158. -- Perform special check for default discoveryURL
  1159. IF @useType = N'businessEntity'
  1160. BEGIN
  1161. SET @defaultPattern = UPPER(dbo.configValue('DefaultDiscoveryURL') + '[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]')
  1162. -- Check to see if the discoveryURL looks like a default discoveryURL
  1163. IF @discoveryURL NOT LIKE @defaultPattern
  1164. GOTO continueSearch
  1165. -- Extract the businessKey from the discoveryURL
  1166. SET @businessKeyStr = RIGHT(@discoveryURL, 36)
  1167. IF dbo.ISGUID(@businessKeyStr) = 0
  1168. GOTO continueSearch
  1169. SET @businessKey = CAST(@businessKeyStr AS uniqueidentifier)
  1170. -- Check to see if the businessKey exists
  1171. IF NOT EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @businessKey)
  1172. GOTO continueSearch
  1173. -- businessKey exists. See if any existing discoveryURLs exist for useType = businessEntity
  1174. SELECT
  1175. @rows = COUNT(*)
  1176. FROM
  1177. [UDC_discoveryURLs] DU
  1178. JOIN [UDC_businessEntities] BE ON DU.[businessID] = BE.[businessID]
  1179. WHERE
  1180. (BE.[businessKey] = @businessKey) AND
  1181. (DU.[useType] = N'businessEntity')
  1182. IF @rows > 0
  1183. BEGIN
  1184. SET @rows = 0
  1185. GOTO continueSearch
  1186. END
  1187. -- No existing discoveryURLs exist for useType = businessEntity for this business.
  1188. -- Since search argument matches default discoveryURL, add businessKey to list of keys
  1189. INSERT @tempKeys(
  1190. [entityKey])
  1191. VALUES(
  1192. @businessKey)
  1193. -- Continue search, since other businesses could possibly have the same discoveryURL
  1194. END -- default discoveryURL logic
  1195. continueSearch:
  1196. SET @contextRows = dbo.contextRows(@contextID)
  1197. IF LEN(@useType) = 0 OR @useType IS NULL
  1198. BEGIN
  1199. SET @useType = '%'
  1200. END
  1201. IF @contextRows = 0
  1202. BEGIN
  1203. INSERT INTO @tempKeys(
  1204. [entityKey])
  1205. SELECT
  1206. BE.[businessKey]
  1207. FROM
  1208. [UDC_businessEntities] BE
  1209. JOIN [UDC_discoveryURLs] DU ON BE.[businessID] = DU.[businessID]
  1210. WHERE
  1211. (DU.[discoveryURL] = @discoveryURL) AND
  1212. ((ISNULL(DU.[useType],'[[NULL]]')) LIKE @useType)
  1213. END
  1214. ELSE
  1215. BEGIN
  1216. INSERT INTO @tempKeys(
  1217. [entityKey])
  1218. SELECT
  1219. BE.[businessKey]
  1220. FROM
  1221. [UDC_businessEntities] BE
  1222. JOIN [UDC_discoveryURLs] DU ON BE.[businessID] = DU.[businessID]
  1223. WHERE
  1224. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1225. (DU.[discoveryURL] = @discoveryURL) AND
  1226. ((ISNULL(DU.[useType],'[[NULL]]')) LIKE @useType)
  1227. END
  1228. -- All keys are combined using logical OR for discoveryURL search arguments
  1229. INSERT [UDS_findScratch] (
  1230. [contextID],
  1231. [entityKey])
  1232. SELECT DISTINCT
  1233. @contextID,
  1234. [entityKey]
  1235. FROM
  1236. @tempKeys
  1237. WHERE
  1238. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1239. SET @rows = @@ROWCOUNT
  1240. RETURN 0
  1241. errorLabel:
  1242. RAISERROR (@error, 16, 1, @context)
  1243. RETURN 1
  1244. END -- net_find_businessEntity_discoveryURL
  1245. GO
  1246. -- =============================================
  1247. -- Name: net_find_businessEntity_identifierBag
  1248. -- =============================================
  1249. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessEntity_identifierBag' AND type = 'P')
  1250. DROP PROCEDURE net_find_businessEntity_identifierBag
  1251. GO
  1252. CREATE PROCEDURE net_find_businessEntity_identifierBag
  1253. @contextID uniqueidentifier,
  1254. @keyName nvarchar(4000),
  1255. @keyValue nvarchar(4000),
  1256. @tModelKey uniqueidentifier,
  1257. @orKeys bit = 0,
  1258. @rows int OUTPUT
  1259. WITH ENCRYPTION
  1260. AS
  1261. BEGIN
  1262. DECLARE
  1263. @error int,
  1264. @context nvarchar(4000),
  1265. @contextRows int
  1266. DECLARE @tempKeys TABLE(
  1267. [entityKey] uniqueidentifier)
  1268. SET @contextRows = dbo.contextRows(@contextID)
  1269. IF @contextRows = 0
  1270. BEGIN
  1271. INSERT @tempKeys(
  1272. [entityKey])
  1273. SELECT DISTINCT
  1274. [businessKey]
  1275. FROM
  1276. [UDC_businessEntities] BE
  1277. JOIN [UDC_identifierBag_BE] IB ON BE.[businessID] = IB.[businessID]
  1278. WHERE
  1279. ([tModelKey] = @tModelKey) AND
  1280. ([keyValue] = @keyValue)
  1281. END
  1282. ELSE
  1283. BEGIN
  1284. INSERT @tempKeys(
  1285. [entityKey])
  1286. SELECT DISTINCT
  1287. [businessKey]
  1288. FROM
  1289. [UDC_businessEntities] BE
  1290. JOIN [UDC_identifierBag_BE] IB ON BE.[businessID] = IB.[businessID]
  1291. WHERE
  1292. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1293. ([tModelKey] = @tModelKey) AND
  1294. ([keyValue] = @keyValue)
  1295. END
  1296. IF @orKeys = 1
  1297. BEGIN
  1298. INSERT [UDS_findScratch] (
  1299. [contextID],
  1300. [entityKey])
  1301. SELECT DISTINCT
  1302. @contextID,
  1303. [entityKey]
  1304. FROM
  1305. @tempKeys
  1306. WHERE
  1307. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1308. END
  1309. ELSE
  1310. BEGIN
  1311. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  1312. BEGIN
  1313. DELETE
  1314. [UDS_findScratch]
  1315. WHERE
  1316. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  1317. END
  1318. ELSE
  1319. BEGIN
  1320. INSERT [UDS_findScratch] (
  1321. [contextID],
  1322. [entityKey])
  1323. SELECT DISTINCT
  1324. @contextID,
  1325. [entityKey]
  1326. FROM
  1327. @tempKeys
  1328. END
  1329. END
  1330. SELECT
  1331. @rows = COUNT(*)
  1332. FROM
  1333. [UDS_findScratch]
  1334. WHERE
  1335. ([contextID] = @contextID)
  1336. RETURN 0
  1337. errorLabel:
  1338. RAISERROR (@error, 16, 1, @context)
  1339. RETURN 1
  1340. END -- net_find_businessEntity_identifierBag
  1341. GO
  1342. -- =============================================
  1343. -- Name: net_find_businessEntity_categoryBag
  1344. -- =============================================
  1345. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessEntity_categoryBag' AND type = 'P')
  1346. DROP PROCEDURE net_find_businessEntity_categoryBag
  1347. GO
  1348. CREATE PROCEDURE net_find_businessEntity_categoryBag
  1349. @contextID uniqueidentifier,
  1350. @keyName nvarchar(4000),
  1351. @keyValue nvarchar(4000),
  1352. @tModelKey uniqueidentifier,
  1353. @orKeys bit = 0,
  1354. @rows int OUTPUT
  1355. WITH ENCRYPTION
  1356. AS
  1357. BEGIN
  1358. DECLARE
  1359. @error int,
  1360. @context nvarchar(4000),
  1361. @contextRows int,
  1362. @genKeywordsMatch bit
  1363. DECLARE @tempKeys TABLE(
  1364. [entityKey] uniqueidentifier)
  1365. SET @contextRows = dbo.contextRows(@contextID)
  1366. SET @genKeywordsMatch = 0
  1367. IF @tModelKey = dbo.genKeywordsKey()
  1368. SET @genKeywordsMatch = 1
  1369. IF @contextRows = 0
  1370. BEGIN
  1371. IF @genKeywordsMatch = 0
  1372. BEGIN
  1373. -- Ignore keyName
  1374. INSERT @tempKeys(
  1375. [entityKey])
  1376. SELECT DISTINCT
  1377. [businessKey]
  1378. FROM
  1379. [UDC_businessEntities] BE
  1380. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1381. WHERE
  1382. ([tModelKey] = @tModelKey) AND
  1383. ([keyValue] = @keyValue)
  1384. END
  1385. ELSE
  1386. BEGIN
  1387. -- Include keyName
  1388. INSERT @tempKeys(
  1389. [entityKey])
  1390. SELECT DISTINCT
  1391. [businessKey]
  1392. FROM
  1393. [UDC_businessEntities] BE
  1394. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1395. WHERE
  1396. ([tModelKey] = @tModelKey) AND
  1397. ([keyValue] = @keyValue) AND
  1398. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1399. END
  1400. END
  1401. ELSE
  1402. BEGIN
  1403. IF @genKeywordsMatch = 0
  1404. BEGIN
  1405. -- Ignore keyName
  1406. INSERT @tempKeys(
  1407. [entityKey])
  1408. SELECT DISTINCT
  1409. [businessKey]
  1410. FROM
  1411. [UDC_businessEntities] BE
  1412. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1413. WHERE
  1414. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1415. ([tModelKey] = @tModelKey) AND
  1416. ([keyValue] = @keyValue)
  1417. END
  1418. ELSE
  1419. BEGIN
  1420. -- Include keyName
  1421. INSERT @tempKeys(
  1422. [entityKey])
  1423. SELECT DISTINCT
  1424. [businessKey]
  1425. FROM
  1426. [UDC_businessEntities] BE
  1427. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1428. WHERE
  1429. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1430. ([tModelKey] = @tModelKey) AND
  1431. ([keyValue] = @keyValue) AND
  1432. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1433. END
  1434. END
  1435. IF @orKeys = 1
  1436. BEGIN
  1437. INSERT [UDS_findScratch] (
  1438. [contextID],
  1439. [entityKey])
  1440. SELECT DISTINCT
  1441. @contextID,
  1442. [entityKey]
  1443. FROM
  1444. @tempKeys
  1445. WHERE
  1446. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1447. END
  1448. ELSE
  1449. BEGIN
  1450. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  1451. BEGIN
  1452. DELETE
  1453. [UDS_findScratch]
  1454. WHERE
  1455. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  1456. END
  1457. ELSE
  1458. BEGIN
  1459. INSERT [UDS_findScratch] (
  1460. [contextID],
  1461. [entityKey])
  1462. SELECT DISTINCT
  1463. @contextID,
  1464. [entityKey]
  1465. FROM
  1466. @tempKeys
  1467. END
  1468. END
  1469. SELECT
  1470. @rows = COUNT(*)
  1471. FROM
  1472. [UDS_findScratch]
  1473. WHERE
  1474. ([contextID] = @contextID)
  1475. RETURN 0
  1476. errorLabel:
  1477. RAISERROR (@error, 16, 1, @context)
  1478. RETURN 1
  1479. END -- net_find_businessEntity_categoryBag
  1480. GO
  1481. -- =============================================
  1482. -- Name: net_find_businessEntity_serviceSubset
  1483. -- =============================================
  1484. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessEntity_serviceSubset' AND type = 'P')
  1485. DROP PROCEDURE net_find_businessEntity_serviceSubset
  1486. GO
  1487. CREATE PROCEDURE net_find_businessEntity_serviceSubset
  1488. @contextID uniqueidentifier,
  1489. @keyName nvarchar(4000),
  1490. @keyValue nvarchar(4000),
  1491. @tModelKey uniqueidentifier,
  1492. @orKeys bit = 0,
  1493. @rows int OUTPUT
  1494. WITH ENCRYPTION
  1495. AS
  1496. BEGIN
  1497. DECLARE
  1498. @error int,
  1499. @context nvarchar(4000),
  1500. @contextRows int,
  1501. @genKeywordsMatch bit
  1502. DECLARE @tempKeys TABLE(
  1503. [entityKey] uniqueidentifier,
  1504. [subEntityKey] uniqueidentifier)
  1505. SET @contextRows = dbo.contextRows(@contextID)
  1506. SET @genKeywordsMatch = 0
  1507. IF @tModelKey = dbo.genKeywordsKey()
  1508. SET @genKeywordsMatch = 1
  1509. IF @contextRows = 0
  1510. BEGIN
  1511. IF @genKeywordsMatch = 1
  1512. BEGIN
  1513. -- Ignore keyName
  1514. -- Standard services
  1515. INSERT @tempKeys(
  1516. [entityKey],
  1517. [subEntityKey])
  1518. SELECT DISTINCT
  1519. BE.[businessKey],
  1520. BS.[serviceKey]
  1521. FROM
  1522. [UDC_businessEntities] BE
  1523. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1524. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1525. WHERE
  1526. (CB.[tModelKey] = @tModelKey) AND
  1527. (CB.[keyValue] = @keyValue)
  1528. -- Projected services
  1529. INSERT @tempKeys(
  1530. [entityKey],
  1531. [subEntityKey])
  1532. SELECT DISTINCT
  1533. BE.[businessKey],
  1534. BS.[serviceKey]
  1535. FROM
  1536. [UDC_businessEntities] BE
  1537. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1538. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1539. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1540. WHERE
  1541. (CB.[tModelKey] = @tModelKey) AND
  1542. (CB.[keyValue] = @keyValue)
  1543. END
  1544. ELSE
  1545. BEGIN
  1546. -- Include keyName
  1547. INSERT @tempKeys(
  1548. [entityKey],
  1549. [subEntityKey])
  1550. SELECT DISTINCT
  1551. BE.[businessKey],
  1552. BS.[serviceKey]
  1553. FROM
  1554. [UDC_businessEntities] BE
  1555. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1556. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1557. WHERE
  1558. (CB.[tModelKey] = @tModelKey) AND
  1559. (CB.[keyValue] = @keyValue) AND
  1560. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1561. -- Projected services
  1562. INSERT @tempKeys(
  1563. [entityKey],
  1564. [subEntityKey])
  1565. SELECT DISTINCT
  1566. BE.[businessKey],
  1567. BS.[serviceKey]
  1568. FROM
  1569. [UDC_businessEntities] BE
  1570. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1571. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1572. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1573. WHERE
  1574. (CB.[tModelKey] = @tModelKey) AND
  1575. (CB.[keyValue] = @keyValue) AND
  1576. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1577. END
  1578. END
  1579. ELSE
  1580. BEGIN
  1581. IF @genKeywordsMatch = 1
  1582. BEGIN
  1583. -- Ignore keyName
  1584. -- Standard services
  1585. INSERT @tempKeys(
  1586. [entityKey],
  1587. [subEntityKey])
  1588. SELECT DISTINCT
  1589. BE.[businessKey],
  1590. BS.[serviceKey]
  1591. FROM
  1592. [UDC_businessEntities] BE
  1593. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1594. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1595. WHERE
  1596. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1597. (CB.[tModelKey] = @tModelKey) AND
  1598. (CB.[keyValue] = @keyValue)
  1599. -- Projected services
  1600. INSERT @tempKeys(
  1601. [entityKey],
  1602. [subEntityKey])
  1603. SELECT DISTINCT
  1604. BE.[businessKey],
  1605. BS.[serviceKey]
  1606. FROM
  1607. [UDC_businessEntities] BE
  1608. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1609. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1610. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1611. WHERE
  1612. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1613. (CB.[tModelKey] = @tModelKey) AND
  1614. (CB.[keyValue] = @keyValue)
  1615. END
  1616. ELSE
  1617. BEGIN
  1618. -- Include keyName
  1619. -- Standard services
  1620. INSERT @tempKeys(
  1621. [entityKey],
  1622. [subEntityKey])
  1623. SELECT DISTINCT
  1624. BE.[businessKey],
  1625. BS.[serviceKey]
  1626. FROM
  1627. [UDC_businessEntities] BE
  1628. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1629. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1630. WHERE
  1631. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1632. (CB.[tModelKey] = @tModelKey) AND
  1633. (CB.[keyValue] = @keyValue) AND
  1634. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1635. -- Projected services
  1636. INSERT @tempKeys(
  1637. [entityKey],
  1638. [subEntityKey])
  1639. SELECT DISTINCT
  1640. BE.[businessKey],
  1641. BS.[serviceKey]
  1642. FROM
  1643. [UDC_businessEntities] BE
  1644. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1645. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1646. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1647. WHERE
  1648. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1649. (CB.[tModelKey] = @tModelKey) AND
  1650. (CB.[keyValue] = @keyValue) AND
  1651. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1652. END
  1653. END
  1654. IF @orKeys = 1
  1655. BEGIN
  1656. INSERT [UDS_findScratch] (
  1657. [contextID],
  1658. [entityKey],
  1659. [subEntityKey])
  1660. SELECT DISTINCT
  1661. @contextID,
  1662. [entityKey],
  1663. [subEntityKey]
  1664. FROM
  1665. @tempKeys
  1666. WHERE
  1667. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1668. END
  1669. ELSE
  1670. BEGIN
  1671. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  1672. BEGIN
  1673. DELETE
  1674. [UDS_findScratch]
  1675. WHERE
  1676. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  1677. END
  1678. ELSE
  1679. BEGIN
  1680. INSERT [UDS_findScratch] (
  1681. [contextID],
  1682. [entityKey],
  1683. [subEntityKey])
  1684. SELECT DISTINCT
  1685. @contextID,
  1686. [entityKey],
  1687. [subEntityKey]
  1688. FROM
  1689. @tempKeys
  1690. END
  1691. END
  1692. SELECT
  1693. @rows = COUNT(*)
  1694. FROM
  1695. [UDS_findScratch]
  1696. WHERE
  1697. ([contextID] = @contextID)
  1698. RETURN 0
  1699. errorLabel:
  1700. RAISERROR (@error, 16, 1, @context)
  1701. RETURN 1
  1702. END -- net_find_businessEntity_serviceSubset
  1703. GO
  1704. -- =============================================
  1705. -- Name: net_find_businessEntity_combineCategoryBags
  1706. -- =============================================
  1707. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessEntity_combineCategoryBags' AND type = 'P')
  1708. DROP PROCEDURE net_find_businessEntity_combineCategoryBags
  1709. GO
  1710. CREATE PROCEDURE net_find_businessEntity_combineCategoryBags
  1711. @contextID uniqueidentifier,
  1712. @keyName nvarchar(4000),
  1713. @keyValue nvarchar(4000),
  1714. @tModelKey uniqueidentifier,
  1715. @orKeys bit = 0,
  1716. @rows int OUTPUT
  1717. WITH ENCRYPTION
  1718. AS
  1719. BEGIN
  1720. DECLARE
  1721. @error int,
  1722. @context nvarchar(4000),
  1723. @contextRows int,
  1724. @genKeywordsMatch bit
  1725. DECLARE @tempKeys TABLE(
  1726. [entityKey] uniqueidentifier)
  1727. SET @contextRows = dbo.contextRows(@contextID)
  1728. SET @genKeywordsMatch = 0
  1729. IF @tModelKey = dbo.genKeywordsKey()
  1730. SET @genKeywordsMatch = 1
  1731. IF @contextRows = 0
  1732. BEGIN
  1733. IF @genKeywordsMatch = 0
  1734. BEGIN
  1735. -- Ignore keyName
  1736. -- businessEntity
  1737. INSERT @tempKeys(
  1738. [entityKey])
  1739. SELECT DISTINCT
  1740. [businessKey]
  1741. FROM
  1742. [UDC_businessEntities] BE
  1743. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1744. WHERE
  1745. ([tModelKey] = @tModelKey) AND
  1746. ([keyValue] = @keyValue)
  1747. -- Standard services
  1748. INSERT @tempKeys(
  1749. [entityKey])
  1750. SELECT DISTINCT
  1751. [businessKey]
  1752. FROM
  1753. [UDC_businessEntities] BE
  1754. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1755. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1756. WHERE
  1757. ([tModelKey] = @tModelKey) AND
  1758. ([keyValue] = @keyValue)
  1759. -- Projected services
  1760. INSERT @tempKeys(
  1761. [entityKey])
  1762. SELECT DISTINCT
  1763. BE.[businessKey]
  1764. FROM
  1765. [UDC_businessEntities] BE
  1766. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1767. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1768. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1769. WHERE
  1770. (CB.[tModelKey] = @tModelKey) AND
  1771. (CB.[keyValue] = @keyValue)
  1772. END
  1773. ELSE
  1774. BEGIN
  1775. -- Include keyName
  1776. -- businessEntity
  1777. INSERT @tempKeys(
  1778. [entityKey])
  1779. SELECT DISTINCT
  1780. [businessKey]
  1781. FROM
  1782. [UDC_businessEntities] BE
  1783. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1784. WHERE
  1785. ([tModelKey] = @tModelKey) AND
  1786. ([keyValue] = @keyValue) AND
  1787. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1788. -- Standard services
  1789. INSERT @tempKeys(
  1790. [entityKey])
  1791. SELECT DISTINCT
  1792. [businessKey]
  1793. FROM
  1794. [UDC_businessEntities] BE
  1795. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1796. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1797. WHERE
  1798. ([tModelKey] = @tModelKey) AND
  1799. ([keyValue] = @keyValue) AND
  1800. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1801. -- Projected services
  1802. INSERT @tempKeys(
  1803. [entityKey])
  1804. SELECT DISTINCT
  1805. BE.[businessKey]
  1806. FROM
  1807. [UDC_businessEntities] BE
  1808. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1809. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1810. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1811. WHERE
  1812. (CB.[tModelKey] = @tModelKey) AND
  1813. (CB.[keyValue] = @keyValue) AND
  1814. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1815. END
  1816. END
  1817. ELSE
  1818. BEGIN
  1819. IF @genKeywordsMatch = 0
  1820. BEGIN
  1821. -- Ignore keyName
  1822. -- businessEntity
  1823. INSERT @tempKeys(
  1824. [entityKey])
  1825. SELECT DISTINCT
  1826. [businessKey]
  1827. FROM
  1828. [UDC_businessEntities] BE
  1829. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1830. WHERE
  1831. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1832. ([tModelKey] = @tModelKey) AND
  1833. ([keyValue] = @keyValue)
  1834. -- Standard services
  1835. INSERT @tempKeys(
  1836. [entityKey])
  1837. SELECT DISTINCT
  1838. [businessKey]
  1839. FROM
  1840. [UDC_businessEntities] BE
  1841. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1842. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1843. WHERE
  1844. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1845. ([tModelKey] = @tModelKey) AND
  1846. ([keyValue] = @keyValue)
  1847. -- Projected services
  1848. INSERT @tempKeys(
  1849. [entityKey])
  1850. SELECT DISTINCT
  1851. BE.[businessKey]
  1852. FROM
  1853. [UDC_businessEntities] BE
  1854. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1855. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1856. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1857. WHERE
  1858. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1859. (CB.[tModelKey] = @tModelKey) AND
  1860. (CB.[keyValue] = @keyValue)
  1861. END
  1862. ELSE
  1863. BEGIN
  1864. -- Include keyName
  1865. -- businessEntity
  1866. INSERT @tempKeys(
  1867. [entityKey])
  1868. SELECT DISTINCT
  1869. [businessKey]
  1870. FROM
  1871. [UDC_businessEntities] BE
  1872. JOIN [UDC_categoryBag_BE] CB ON BE.[businessID] = CB.[businessID]
  1873. WHERE
  1874. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1875. ([tModelKey] = @tModelKey) AND
  1876. ([keyValue] = @keyValue) AND
  1877. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1878. -- Standard services
  1879. INSERT @tempKeys(
  1880. [entityKey])
  1881. SELECT DISTINCT
  1882. [businessKey]
  1883. FROM
  1884. [UDC_businessEntities] BE
  1885. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1886. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1887. WHERE
  1888. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1889. ([tModelKey] = @tModelKey) AND
  1890. ([keyValue] = @keyValue) AND
  1891. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1892. -- Projected services
  1893. INSERT @tempKeys(
  1894. [entityKey])
  1895. SELECT DISTINCT
  1896. BE.[businessKey]
  1897. FROM
  1898. [UDC_businessEntities] BE
  1899. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  1900. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  1901. JOIN [UDC_categoryBag_BS] CB ON BS.[serviceID] = CB.[serviceID]
  1902. WHERE
  1903. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  1904. (CB.[tModelKey] = @tModelKey) AND
  1905. (CB.[keyValue] = @keyValue) AND
  1906. (ISNULL([keyName],'') = ISNULL(@keyName,''))
  1907. END
  1908. END
  1909. IF @orKeys = 1
  1910. BEGIN
  1911. INSERT [UDS_findScratch] (
  1912. [contextID],
  1913. [entityKey])
  1914. SELECT DISTINCT
  1915. @contextID,
  1916. [entityKey]
  1917. FROM
  1918. @tempKeys
  1919. WHERE
  1920. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  1921. END
  1922. ELSE
  1923. BEGIN
  1924. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  1925. BEGIN
  1926. DELETE
  1927. [UDS_findScratch]
  1928. WHERE
  1929. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  1930. END
  1931. ELSE
  1932. BEGIN
  1933. INSERT [UDS_findScratch] (
  1934. [contextID],
  1935. [entityKey])
  1936. SELECT DISTINCT
  1937. @contextID,
  1938. [entityKey]
  1939. FROM
  1940. @tempKeys
  1941. END
  1942. END
  1943. SELECT
  1944. @rows = COUNT(*)
  1945. FROM
  1946. [UDS_findScratch]
  1947. WHERE
  1948. ([contextID] = @contextID)
  1949. RETURN 0
  1950. errorLabel:
  1951. RAISERROR (@error, 16, 1, @context)
  1952. RETURN 1
  1953. END -- net_find_businessEntity_combineCategoryBags
  1954. GO
  1955. -- =============================================
  1956. -- Name: net_find_businessEntity_tModelBag
  1957. -- =============================================
  1958. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessEntity_tModelBag' AND type = 'P')
  1959. DROP PROCEDURE net_find_businessEntity_tModelBag
  1960. GO
  1961. CREATE PROCEDURE net_find_businessEntity_tModelBag
  1962. @contextID uniqueidentifier,
  1963. @tModelKey uniqueidentifier,
  1964. @orKeys bit = 0,
  1965. @rows int OUTPUT
  1966. WITH ENCRYPTION
  1967. AS
  1968. BEGIN
  1969. DECLARE
  1970. @error int,
  1971. @context nvarchar(4000),
  1972. @contextRows int
  1973. DECLARE @tempKeys TABLE(
  1974. [entityKey] uniqueidentifier)
  1975. -- See if we have any results from a search against another bag (ie. categoryBag or identifierBag)
  1976. SET @contextRows = dbo.contextRows(@contextID)
  1977. IF @contextRows = 0
  1978. -- If there are no previous results we can just query and insert into @tempKeys
  1979. BEGIN
  1980. --
  1981. -- First check contained services
  1982. --
  1983. -- check tModelInstances
  1984. INSERT @tempKeys(
  1985. [entityKey])
  1986. SELECT DISTINCT
  1987. BE.[businessKey]
  1988. FROM
  1989. [UDC_businessEntities] BE
  1990. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  1991. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  1992. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  1993. WHERE
  1994. (TI.[tModelKey] = @tModelKey)
  1995. -- Check hostingRedirectors
  1996. INSERT @tempKeys(
  1997. [entityKey])
  1998. SELECT DISTINCT
  1999. BE.[businessKey]
  2000. FROM
  2001. [UDC_businessEntities] BE
  2002. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  2003. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  2004. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  2005. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  2006. WHERE
  2007. (TI.[tModelKey] = @tModelKey)
  2008. --
  2009. -- Next check projected services
  2010. --
  2011. -- check tModelInstances
  2012. INSERT @tempKeys(
  2013. [entityKey])
  2014. SELECT DISTINCT
  2015. BE.[businessKey]
  2016. FROM
  2017. [UDC_businessEntities] BE
  2018. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  2019. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  2020. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  2021. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  2022. WHERE
  2023. (TI.[tModelKey] = @tModelKey)
  2024. -- Check hostingRedirectors
  2025. INSERT @tempKeys(
  2026. [entityKey])
  2027. SELECT DISTINCT
  2028. BE.[businessKey]
  2029. FROM
  2030. [UDC_businessEntities] BE
  2031. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  2032. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  2033. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  2034. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  2035. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  2036. WHERE
  2037. (TI.[tModelKey] = @tModelKey)
  2038. END
  2039. ELSE
  2040. -- If there are previous results from searches against other bags, then we must take that into account in the
  2041. -- queries for this bag. This is necessary because results between bags are always 'AND-ed'.
  2042. BEGIN
  2043. --
  2044. -- First check contained services
  2045. --
  2046. -- check tModelInstances
  2047. INSERT @tempKeys(
  2048. [entityKey])
  2049. SELECT DISTINCT
  2050. BE.[businessKey]
  2051. FROM
  2052. [UDC_businessEntities] BE
  2053. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  2054. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  2055. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  2056. WHERE
  2057. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  2058. (TI.[tModelKey] = @tModelKey)
  2059. -- Check hostingRedirectors
  2060. INSERT @tempKeys(
  2061. [entityKey])
  2062. SELECT DISTINCT
  2063. BE.[businessKey]
  2064. FROM
  2065. [UDC_businessEntities] BE
  2066. JOIN [UDC_businessServices] BS ON BE.[businessID] = BS.[businessID]
  2067. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  2068. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  2069. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  2070. WHERE
  2071. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  2072. (TI.[tModelKey] = @tModelKey)
  2073. --
  2074. -- Next check projected services
  2075. --
  2076. -- check tModelInstances
  2077. INSERT @tempKeys(
  2078. [entityKey])
  2079. SELECT DISTINCT
  2080. BE.[businessKey]
  2081. FROM
  2082. [UDC_businessEntities] BE
  2083. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  2084. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  2085. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  2086. JOIN [UDC_tModelInstances] TI ON BT.[bindingID] = TI.[bindingID]
  2087. WHERE
  2088. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  2089. (TI.[tModelKey] = @tModelKey)
  2090. -- Check hostingRedirectors
  2091. INSERT @tempKeys(
  2092. [entityKey])
  2093. SELECT DISTINCT
  2094. BE.[businessKey]
  2095. FROM
  2096. [UDC_businessEntities] BE
  2097. JOIN [UDC_serviceProjections] SP ON BE.[businessKey] = SP.[businessKey]
  2098. JOIN [UDC_businessServices] BS ON SP.[serviceKey] = BS.[serviceKey]
  2099. JOIN [UDC_bindingTemplates] BT ON BS.[serviceID] = BT.[serviceID]
  2100. JOIN [UDC_bindingTemplates] BT2 ON BT.[hostingRedirector] = BT2.[bindingKey]
  2101. JOIN [UDC_tModelInstances] TI ON BT2.[bindingID] = TI.[bindingID]
  2102. WHERE
  2103. (BE.[businessKey] IN (SELECT [entityKey] FROM [UDS_findResults] WHERE ([contextID] = @contextID))) AND
  2104. (TI.[tModelKey] = @tModelKey)
  2105. END
  2106. IF @orKeys = 1
  2107. BEGIN
  2108. -- OR operation between @tempKeys and the UDS_findScratch table
  2109. INSERT [UDS_findScratch] (
  2110. [contextID],
  2111. [entityKey])
  2112. SELECT DISTINCT
  2113. @contextID,
  2114. [entityKey]
  2115. FROM
  2116. @tempKeys
  2117. WHERE
  2118. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  2119. END
  2120. ELSE
  2121. BEGIN
  2122. -- AND operation between @tempKeys and the UDS_findScratch table
  2123. IF EXISTS(SELECT * FROM [UDS_findScratch] WHERE [contextID] = @contextID)
  2124. BEGIN
  2125. DELETE
  2126. [UDS_findScratch]
  2127. WHERE
  2128. ([entityKey] NOT IN (SELECT [entityKey] FROM @tempKeys WHERE [contextID] = @contextID))
  2129. END
  2130. ELSE
  2131. BEGIN
  2132. INSERT [UDS_findScratch] (
  2133. [contextID],
  2134. [entityKey])
  2135. SELECT DISTINCT
  2136. @contextID,
  2137. [entityKey]
  2138. FROM
  2139. @tempKeys
  2140. END
  2141. END
  2142. SELECT
  2143. @rows = COUNT(*)
  2144. FROM
  2145. [UDS_findScratch]
  2146. WHERE
  2147. ([contextID] = @contextID)
  2148. RETURN 0
  2149. errorLabel:
  2150. RAISERROR (@error, 16, 1, @context)
  2151. RETURN 1
  2152. END -- net_find_businessEntity_tModelBag
  2153. GO
  2154. -- =============================================
  2155. -- Name: net_find_businessEntity_commit
  2156. -- =============================================
  2157. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_businessEntity_commit' AND type = 'P')
  2158. DROP PROCEDURE net_find_businessEntity_commit
  2159. GO
  2160. CREATE PROCEDURE net_find_businessEntity_commit
  2161. @contextID uniqueidentifier,
  2162. @sortByNameAsc bit,
  2163. @sortByNameDesc bit,
  2164. @sortByDateAsc bit,
  2165. @sortByDateDesc bit,
  2166. @maxRows int,
  2167. @truncated int OUTPUT
  2168. WITH ENCRYPTION
  2169. AS
  2170. BEGIN
  2171. -- Finalizes a find_business and returns a key list
  2172. DECLARE
  2173. @error int,
  2174. @context nvarchar(4000),
  2175. @contextRows int
  2176. SET @contextRows = dbo.contextRows(@contextID)
  2177. SET @truncated = 0
  2178. IF @contextRows = 0
  2179. RETURN 0
  2180. DECLARE @tempKeys TABLE (
  2181. [seqNo] bigint IDENTITY PRIMARY KEY ,
  2182. [entityKey] uniqueidentifier,
  2183. [name] nvarchar(450) NULL,
  2184. [lastChange] bigint NULL,
  2185. [businessID] bigint NULL)
  2186. -- Set default sorting option
  2187. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0) AND (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2188. SET @sortByNameAsc = 1
  2189. -- Set maxRows if default was passed
  2190. IF ISNULL(@maxRows,0) = 0
  2191. SET @maxRows = dbo.configValue('Find.MaxRowsDefault')
  2192. -- sortByNameAsc
  2193. IF (@sortByNameAsc = 1)
  2194. BEGIN
  2195. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2196. SET @sortByDateAsc = 1
  2197. IF (@sortByDateAsc = 1)
  2198. BEGIN
  2199. INSERT @tempKeys(
  2200. [entityKey],
  2201. [name],
  2202. [lastChange],
  2203. [businessID])
  2204. SELECT DISTINCT
  2205. FR.[entityKey],
  2206. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2207. BE.[lastChange],
  2208. BE.[businessID]
  2209. FROM
  2210. [UDS_findResults] FR
  2211. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2212. WHERE
  2213. (@contextID = FR.[contextID])
  2214. ORDER BY
  2215. 2 ASC,
  2216. 3 ASC,
  2217. 4 ASC
  2218. END
  2219. ELSE
  2220. BEGIN
  2221. INSERT @tempKeys(
  2222. [entityKey],
  2223. [name],
  2224. [lastChange],
  2225. [businessID])
  2226. SELECT DISTINCT
  2227. FR.[entityKey],
  2228. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2229. BE.[lastChange],
  2230. BE.[businessID]
  2231. FROM
  2232. [UDS_findResults] FR
  2233. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2234. WHERE
  2235. (@contextID = FR.[contextID])
  2236. ORDER BY
  2237. 2 ASC,
  2238. 3 DESC,
  2239. 4 DESC
  2240. END
  2241. GOTO endLabel
  2242. END
  2243. -- sortByNameDesc
  2244. IF (@sortByNameDesc = 1)
  2245. BEGIN
  2246. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2247. SET @sortByDateAsc = 1
  2248. IF (@sortByDateAsc = 1)
  2249. BEGIN
  2250. INSERT @tempKeys(
  2251. [entityKey],
  2252. [name],
  2253. [lastChange],
  2254. [businessID])
  2255. SELECT DISTINCT
  2256. FR.[entityKey],
  2257. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2258. BE.[lastChange],
  2259. BE.[businessID]
  2260. FROM
  2261. [UDS_findResults] FR
  2262. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2263. WHERE
  2264. (@contextID = FR.[contextID])
  2265. ORDER BY
  2266. 2 DESC,
  2267. 3 ASC,
  2268. 4 ASC
  2269. END
  2270. ELSE
  2271. BEGIN
  2272. INSERT @tempKeys(
  2273. [entityKey],
  2274. [name],
  2275. [lastChange],
  2276. [businessID])
  2277. SELECT DISTINCT
  2278. FR.[entityKey],
  2279. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2280. BE.[lastChange],
  2281. BE.[businessID]
  2282. FROM
  2283. [UDS_findResults] FR
  2284. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2285. WHERE
  2286. (@contextID = FR.[contextID])
  2287. ORDER BY
  2288. 2 DESC,
  2289. 3 DESC,
  2290. 4 DESC
  2291. END
  2292. GOTO endLabel
  2293. END
  2294. -- sortByDateAsc
  2295. IF (@sortByDateAsc = 1)
  2296. BEGIN
  2297. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  2298. SET @sortByNameAsc = 1
  2299. IF (@sortByNameAsc = 1)
  2300. BEGIN
  2301. INSERT @tempKeys(
  2302. [entityKey],
  2303. [name],
  2304. [lastChange],
  2305. [businessID])
  2306. SELECT DISTINCT
  2307. FR.[entityKey],
  2308. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2309. BE.[lastChange],
  2310. BE.[businessID]
  2311. FROM
  2312. [UDS_findResults] FR
  2313. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2314. WHERE
  2315. (@contextID = FR.[contextID])
  2316. ORDER BY
  2317. 3 ASC,
  2318. 4 ASC,
  2319. 2 ASC
  2320. END
  2321. ELSE
  2322. BEGIN
  2323. INSERT @tempKeys(
  2324. [entityKey],
  2325. [name],
  2326. [lastChange],
  2327. [businessID])
  2328. SELECT DISTINCT
  2329. FR.[entityKey],
  2330. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2331. BE.[lastChange],
  2332. BE.[businessID]
  2333. FROM
  2334. [UDS_findResults] FR
  2335. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2336. WHERE
  2337. (@contextID = FR.[contextID])
  2338. ORDER BY
  2339. 3 ASC,
  2340. 4 ASC,
  2341. 2 DESC
  2342. END
  2343. GOTO endLabel
  2344. END
  2345. -- sortByDateDesc
  2346. IF (@sortByDateDesc = 1)
  2347. BEGIN
  2348. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  2349. SET @sortByNameAsc = 1
  2350. IF (@sortByNameAsc = 1)
  2351. BEGIN
  2352. INSERT @tempKeys(
  2353. [entityKey],
  2354. [name],
  2355. [lastChange],
  2356. [businessID])
  2357. SELECT DISTINCT
  2358. FR.[entityKey],
  2359. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2360. BE.[lastChange],
  2361. BE.[businessID]
  2362. FROM
  2363. [UDS_findResults] FR
  2364. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2365. WHERE
  2366. (@contextID = FR.[contextID])
  2367. ORDER BY
  2368. 3 DESC,
  2369. 4 DESC,
  2370. 2 ASC
  2371. END
  2372. ELSE
  2373. BEGIN
  2374. INSERT @tempKeys(
  2375. [entityKey],
  2376. [name],
  2377. [lastChange],
  2378. [businessID])
  2379. SELECT DISTINCT
  2380. FR.[entityKey],
  2381. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2382. BE.[lastChange],
  2383. BE.[businessID]
  2384. FROM
  2385. [UDS_findResults] FR
  2386. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2387. WHERE
  2388. (@contextID = FR.[contextID])
  2389. ORDER BY
  2390. 3 DESC,
  2391. 4 DESC,
  2392. 2 DESC
  2393. END
  2394. GOTO endLabel
  2395. END
  2396. endLabel:
  2397. -- Set @truncated
  2398. IF (SELECT COUNT(*) FROM @tempKeys) > @maxRows
  2399. SET @truncated = 1
  2400. -- Return keys
  2401. SELECT
  2402. [entityKey]
  2403. FROM
  2404. @tempKeys
  2405. WHERE
  2406. ([seqNo] <= @maxRows)
  2407. -- Run cleanup
  2408. EXEC net_find_cleanup @contextID
  2409. RETURN 0
  2410. errorLabel:
  2411. RAISERROR (@error, 16, 1, @context)
  2412. RETURN 1
  2413. END -- net_find_businessEntity_commit
  2414. GO
  2415. -- =============================================
  2416. -- Name: net_find_businessEntity_serviceSubset_commit
  2417. -- =============================================
  2418. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_businessEntity_serviceSubset_commit' AND type = 'P')
  2419. DROP PROCEDURE net_find_businessEntity_serviceSubset_commit
  2420. GO
  2421. CREATE PROCEDURE net_find_businessEntity_serviceSubset_commit
  2422. @contextID uniqueidentifier,
  2423. @sortByNameAsc bit,
  2424. @sortByNameDesc bit,
  2425. @sortByDateAsc bit,
  2426. @sortByDateDesc bit,
  2427. @maxRows int,
  2428. @truncated int OUTPUT
  2429. WITH ENCRYPTION
  2430. AS
  2431. BEGIN
  2432. -- Finalizes a find_business and returns a key list
  2433. DECLARE
  2434. @error int,
  2435. @context nvarchar(4000),
  2436. @contextRows int
  2437. SET @contextRows = dbo.contextRows(@contextID)
  2438. SET @truncated = 0
  2439. IF @contextRows = 0
  2440. RETURN 0
  2441. DECLARE @tempKeys TABLE (
  2442. [seqNo] bigint IDENTITY PRIMARY KEY ,
  2443. [entityKey] uniqueidentifier,
  2444. [name] nvarchar(450) NULL,
  2445. [lastChange] bigint NULL,
  2446. [businessID] bigint NULL)
  2447. -- Set default sorting option
  2448. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0) AND (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2449. SET @sortByNameAsc = 1
  2450. -- Set maxRows if default was passed
  2451. IF ISNULL(@maxRows,0) = 0
  2452. SET @maxRows = dbo.configValue('Find.MaxRowsDefault')
  2453. -- sortByNameAsc
  2454. IF (@sortByNameAsc = 1)
  2455. BEGIN
  2456. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2457. SET @sortByDateAsc = 1
  2458. IF (@sortByDateAsc = 1)
  2459. BEGIN
  2460. INSERT @tempKeys(
  2461. [entityKey],
  2462. [name],
  2463. [lastChange],
  2464. [businessID])
  2465. SELECT DISTINCT
  2466. FR.[entityKey],
  2467. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2468. BE.[lastChange],
  2469. BE.[businessID]
  2470. FROM
  2471. [UDS_findResults] FR
  2472. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2473. WHERE
  2474. (@contextID = FR.[contextID])
  2475. ORDER BY
  2476. 2 ASC,
  2477. 3 ASC,
  2478. 4 ASC
  2479. END
  2480. ELSE
  2481. BEGIN
  2482. INSERT @tempKeys(
  2483. [entityKey],
  2484. [name],
  2485. [lastChange],
  2486. [businessID])
  2487. SELECT DISTINCT
  2488. FR.[entityKey],
  2489. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2490. BE.[lastChange],
  2491. BE.[businessID]
  2492. FROM
  2493. [UDS_findResults] FR
  2494. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2495. WHERE
  2496. (@contextID = FR.[contextID])
  2497. ORDER BY
  2498. 2 ASC,
  2499. 3 DESC,
  2500. 4 DESC
  2501. END
  2502. GOTO endLabel
  2503. END
  2504. -- sortByNameDesc
  2505. IF (@sortByNameDesc = 1)
  2506. BEGIN
  2507. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2508. SET @sortByDateAsc = 1
  2509. IF (@sortByDateAsc = 1)
  2510. BEGIN
  2511. INSERT @tempKeys(
  2512. [entityKey],
  2513. [name],
  2514. [lastChange],
  2515. [businessID])
  2516. SELECT DISTINCT
  2517. FR.[entityKey],
  2518. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2519. BE.[lastChange],
  2520. BE.[businessID]
  2521. FROM
  2522. [UDS_findResults] FR
  2523. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2524. WHERE
  2525. (@contextID = FR.[contextID])
  2526. ORDER BY
  2527. 2 DESC,
  2528. 3 ASC,
  2529. 4 ASC
  2530. END
  2531. ELSE
  2532. BEGIN
  2533. INSERT @tempKeys(
  2534. [entityKey],
  2535. [name],
  2536. [lastChange],
  2537. [businessID])
  2538. SELECT DISTINCT
  2539. FR.[entityKey],
  2540. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2541. BE.[lastChange],
  2542. BE.[businessID]
  2543. FROM
  2544. [UDS_findResults] FR
  2545. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2546. WHERE
  2547. (@contextID = FR.[contextID])
  2548. ORDER BY
  2549. 2 DESC,
  2550. 3 DESC,
  2551. 4 DESC
  2552. END
  2553. GOTO endLabel
  2554. END
  2555. -- sortByDateAsc
  2556. IF (@sortByDateAsc = 1)
  2557. BEGIN
  2558. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  2559. SET @sortByNameAsc = 1
  2560. IF (@sortByNameAsc = 1)
  2561. BEGIN
  2562. INSERT @tempKeys(
  2563. [entityKey],
  2564. [name],
  2565. [lastChange],
  2566. [businessID])
  2567. SELECT DISTINCT
  2568. FR.[entityKey],
  2569. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2570. BE.[lastChange],
  2571. BE.[businessID]
  2572. FROM
  2573. [UDS_findResults] FR
  2574. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2575. WHERE
  2576. (@contextID = FR.[contextID])
  2577. ORDER BY
  2578. 3 ASC,
  2579. 4 ASC,
  2580. 2 ASC
  2581. END
  2582. ELSE
  2583. BEGIN
  2584. INSERT @tempKeys(
  2585. [entityKey],
  2586. [name],
  2587. [lastChange],
  2588. [businessID])
  2589. SELECT DISTINCT
  2590. FR.[entityKey],
  2591. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2592. BE.[lastChange],
  2593. BE.[businessID]
  2594. FROM
  2595. [UDS_findResults] FR
  2596. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2597. WHERE
  2598. (@contextID = FR.[contextID])
  2599. ORDER BY
  2600. 3 ASC,
  2601. 4 ASC,
  2602. 2 DESC
  2603. END
  2604. GOTO endLabel
  2605. END
  2606. -- sortByDateDesc
  2607. IF (@sortByDateDesc = 1)
  2608. BEGIN
  2609. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  2610. SET @sortByNameAsc = 1
  2611. IF (@sortByNameAsc = 1)
  2612. BEGIN
  2613. INSERT @tempKeys(
  2614. [entityKey],
  2615. [name],
  2616. [lastChange],
  2617. [businessID])
  2618. SELECT DISTINCT
  2619. FR.[entityKey],
  2620. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2621. BE.[lastChange],
  2622. BE.[businessID]
  2623. FROM
  2624. [UDS_findResults] FR
  2625. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2626. WHERE
  2627. (@contextID = FR.[contextID])
  2628. ORDER BY
  2629. 3 DESC,
  2630. 4 DESC,
  2631. 2 ASC
  2632. END
  2633. ELSE
  2634. BEGIN
  2635. INSERT @tempKeys(
  2636. [entityKey],
  2637. [name],
  2638. [lastChange],
  2639. [businessID])
  2640. SELECT DISTINCT
  2641. FR.[entityKey],
  2642. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2643. BE.[lastChange],
  2644. BE.[businessID]
  2645. FROM
  2646. [UDS_findResults] FR
  2647. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2648. WHERE
  2649. (@contextID = FR.[contextID])
  2650. ORDER BY
  2651. 3 DESC,
  2652. 4 DESC,
  2653. 2 DESC
  2654. END
  2655. GOTO endLabel
  2656. END
  2657. endLabel:
  2658. -- Set @truncated
  2659. IF (SELECT COUNT(*) FROM @tempKeys) > @maxRows
  2660. SET @truncated = 1
  2661. -- Return keys
  2662. SELECT
  2663. TK.[entityKey],
  2664. FR.[subEntityKey]
  2665. FROM
  2666. @tempKeys TK
  2667. JOIN [UDS_findResults] FR ON @contextID = FR.[contextID] AND TK.[entityKey] = FR.[entityKey]
  2668. WHERE
  2669. ([seqNo] <= @maxRows)
  2670. ORDER BY
  2671. TK.[seqNo] ASC
  2672. -- Run cleanup
  2673. EXEC net_find_cleanup @contextID
  2674. RETURN 0
  2675. errorLabel:
  2676. RAISERROR (@error, 16, 1, @context)
  2677. RETURN 1
  2678. END -- net_find_businessEntity_serviceSubset_commit
  2679. GO
  2680. -- =============================================
  2681. -- Name: net_find_businessEntity_relatedBusinesses
  2682. -- =============================================
  2683. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_businessEntity_relatedBusinesses' AND type = 'P')
  2684. DROP PROCEDURE net_find_businessEntity_relatedBusinesses
  2685. GO
  2686. CREATE PROCEDURE net_find_businessEntity_relatedBusinesses
  2687. @contextID uniqueidentifier,
  2688. @businessKey uniqueidentifier,
  2689. @keyName nvarchar(4000) = NULL,
  2690. @keyValue nvarchar(4000) = NULL,
  2691. @tModelKey uniqueidentifier = NULL,
  2692. @sortByNameAsc bit,
  2693. @sortByNameDesc bit,
  2694. @sortByDateAsc bit,
  2695. @sortByDateDesc bit,
  2696. @maxRows int,
  2697. @truncated int OUTPUT,
  2698. @rows int OUTPUT
  2699. WITH ENCRYPTION
  2700. AS
  2701. BEGIN
  2702. DECLARE
  2703. @error int,
  2704. @context nvarchar(4000)
  2705. DECLARE @tempKeys TABLE(
  2706. [seqNo] bigint IDENTITY PRIMARY KEY,
  2707. [entityKey] uniqueidentifier,
  2708. [name] nvarchar(450) NULL,
  2709. [lastChange] bigint NULL,
  2710. [businessID] bigint NULL)
  2711. IF @tModelKey IS NULL
  2712. BEGIN
  2713. -- Perform find without keyedReference
  2714. INSERT [UDS_findResults] (
  2715. [contextID],
  2716. [entityKey])
  2717. SELECT DISTINCT
  2718. @contextID,
  2719. [toKey]
  2720. FROM
  2721. [UDC_assertions_BE]
  2722. WHERE
  2723. ([fromKey] = @businessKey) AND
  2724. ([flag] = 3) -- CompletionStatusType.Complete
  2725. INSERT [UDS_findResults] (
  2726. [contextID],
  2727. [entityKey])
  2728. SELECT DISTINCT
  2729. @contextID,
  2730. [fromKey]
  2731. FROM
  2732. [UDC_assertions_BE]
  2733. WHERE
  2734. ([toKey] = @businessKey) AND
  2735. ([flag] = 3) -- CompletionStatusType.Complete
  2736. END
  2737. ELSE
  2738. BEGIN
  2739. INSERT [UDS_findResults](
  2740. [contextID],
  2741. [entityKey])
  2742. SELECT DISTINCT
  2743. @contextID,
  2744. [toKey]
  2745. FROM
  2746. [UDC_assertions_BE]
  2747. WHERE
  2748. ([fromKey] = @businessKey) AND
  2749. ([tModelKey] = @tModelKey) AND
  2750. ([keyValue] = @keyValue) AND
  2751. (ISNULL([keyName],'') = ISNULL(@keyName,'')) AND
  2752. ([flag] = 3) -- CompletionStatusType.Complete
  2753. INSERT [UDS_findResults](
  2754. [contextID],
  2755. [entityKey])
  2756. SELECT DISTINCT
  2757. @contextID,
  2758. [fromKey]
  2759. FROM
  2760. [UDC_assertions_BE]
  2761. WHERE
  2762. ([toKey] = @businessKey) AND
  2763. ([tModelKey] = @tModelKey) AND
  2764. ([keyValue] = @keyValue) AND
  2765. (ISNULL([keyName],'') = ISNULL(@keyName,'')) AND
  2766. ([flag] = 3) -- CompletionStatusType.Complete
  2767. END
  2768. -- Set default sorting option
  2769. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0) AND (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2770. SET @sortByNameAsc = 1
  2771. -- Set maxRows if default was passed
  2772. IF ISNULL(@maxRows,0) = 0
  2773. SET @maxRows = dbo.configValue('Find.MaxRowsDefault')
  2774. -- sortByNameAsc
  2775. IF (@sortByNameAsc = 1)
  2776. BEGIN
  2777. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2778. SET @sortByDateAsc = 1
  2779. IF (@sortByDateAsc = 1)
  2780. BEGIN
  2781. INSERT @tempKeys(
  2782. [entityKey],
  2783. [name],
  2784. [lastChange],
  2785. [businessID])
  2786. SELECT DISTINCT
  2787. FR.[entityKey],
  2788. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2789. BE.[lastChange],
  2790. BE.[businessID]
  2791. FROM
  2792. [UDS_findResults] FR
  2793. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2794. WHERE
  2795. (@contextID = FR.[contextID])
  2796. ORDER BY
  2797. 2 ASC,
  2798. 3 ASC,
  2799. 4 ASC
  2800. END
  2801. ELSE
  2802. BEGIN
  2803. INSERT @tempKeys(
  2804. [entityKey],
  2805. [name],
  2806. [lastChange],
  2807. [businessID])
  2808. SELECT DISTINCT
  2809. FR.[entityKey],
  2810. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2811. BE.[lastChange],
  2812. BE.[businessID]
  2813. FROM
  2814. [UDS_findResults] FR
  2815. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2816. WHERE
  2817. (@contextID = FR.[contextID])
  2818. ORDER BY
  2819. 2 ASC,
  2820. 3 DESC,
  2821. 4 DESC
  2822. END
  2823. GOTO endLabel
  2824. END
  2825. -- sortByNameDesc
  2826. IF (@sortByNameDesc = 1)
  2827. BEGIN
  2828. IF (@sortByDateAsc = 0) AND (@sortByDateDesc = 0)
  2829. SET @sortByDateAsc = 1
  2830. IF (@sortByDateAsc = 1)
  2831. BEGIN
  2832. INSERT @tempKeys(
  2833. [entityKey],
  2834. [name],
  2835. [lastChange],
  2836. [businessID])
  2837. SELECT DISTINCT
  2838. FR.[entityKey],
  2839. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2840. BE.[lastChange],
  2841. BE.[businessID]
  2842. FROM
  2843. [UDS_findResults] FR
  2844. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2845. WHERE
  2846. (@contextID = FR.[contextID])
  2847. ORDER BY
  2848. 2 DESC,
  2849. 3 ASC,
  2850. 4 ASC
  2851. END
  2852. ELSE
  2853. BEGIN
  2854. INSERT @tempKeys(
  2855. [entityKey],
  2856. [name],
  2857. [lastChange],
  2858. [businessID])
  2859. SELECT DISTINCT
  2860. FR.[entityKey],
  2861. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2862. BE.[lastChange],
  2863. BE.[businessID]
  2864. FROM
  2865. [UDS_findResults] FR
  2866. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2867. WHERE
  2868. (@contextID = FR.[contextID])
  2869. ORDER BY
  2870. 2 DESC,
  2871. 3 DESC,
  2872. 4 DESC
  2873. END
  2874. GOTO endLabel
  2875. END
  2876. -- sortByDateAsc
  2877. IF (@sortByDateAsc = 1)
  2878. BEGIN
  2879. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  2880. SET @sortByNameAsc = 1
  2881. IF (@sortByNameAsc = 1)
  2882. BEGIN
  2883. INSERT @tempKeys(
  2884. [entityKey],
  2885. [name],
  2886. [lastChange],
  2887. [businessID])
  2888. SELECT DISTINCT
  2889. FR.[entityKey],
  2890. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2891. BE.[lastChange],
  2892. BE.[businessID]
  2893. FROM
  2894. [UDS_findResults] FR
  2895. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2896. WHERE
  2897. (@contextID = FR.[contextID])
  2898. ORDER BY
  2899. 3 ASC,
  2900. 4 ASC,
  2901. 2 ASC
  2902. END
  2903. ELSE
  2904. BEGIN
  2905. INSERT @tempKeys(
  2906. [entityKey],
  2907. [name],
  2908. [lastChange],
  2909. [businessID])
  2910. SELECT DISTINCT
  2911. FR.[entityKey],
  2912. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2913. BE.[lastChange],
  2914. BE.[businessID]
  2915. FROM
  2916. [UDS_findResults] FR
  2917. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2918. WHERE
  2919. (@contextID = FR.[contextID])
  2920. ORDER BY
  2921. 3 ASC,
  2922. 4 ASC,
  2923. 2 DESC
  2924. END
  2925. GOTO endLabel
  2926. END
  2927. -- sortByDateDesc
  2928. IF (@sortByDateDesc = 1)
  2929. BEGIN
  2930. IF (@sortByNameAsc = 0) AND (@sortByNameDesc = 0)
  2931. SET @sortByNameAsc = 1
  2932. IF (@sortByNameAsc = 1)
  2933. BEGIN
  2934. INSERT @tempKeys(
  2935. [entityKey],
  2936. [name],
  2937. [lastChange],
  2938. [businessID])
  2939. SELECT DISTINCT
  2940. FR.[entityKey],
  2941. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2942. BE.[lastChange],
  2943. BE.[businessID]
  2944. FROM
  2945. [UDS_findResults] FR
  2946. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2947. WHERE
  2948. (@contextID = FR.[contextID])
  2949. ORDER BY
  2950. 3 DESC,
  2951. 4 DESC,
  2952. 2 ASC
  2953. END
  2954. ELSE
  2955. BEGIN
  2956. INSERT @tempKeys(
  2957. [entityKey],
  2958. [name],
  2959. [lastChange],
  2960. [businessID])
  2961. SELECT DISTINCT
  2962. FR.[entityKey],
  2963. (SELECT TOP 1 [name] FROM [UDC_names_BE] WHERE ([businessID] = dbo.businessID([entityKey]))),
  2964. BE.[lastChange],
  2965. BE.[businessID]
  2966. FROM
  2967. [UDS_findResults] FR
  2968. JOIN [UDC_businessEntities] BE ON FR.[entityKey] = BE.[businessKey]
  2969. WHERE
  2970. (@contextID = FR.[contextID])
  2971. ORDER BY
  2972. 3 DESC,
  2973. 4 DESC,
  2974. 2 DESC
  2975. END
  2976. GOTO endLabel
  2977. END
  2978. endLabel:
  2979. -- Set @truncated
  2980. SELECT
  2981. @rows = COUNT(*)
  2982. FROM
  2983. @tempKeys
  2984. IF @rows > @maxRows
  2985. SET @truncated = 1
  2986. -- Return keys
  2987. SELECT
  2988. [entityKey]
  2989. FROM
  2990. @tempKeys
  2991. WHERE
  2992. ([seqNo] <= @maxRows)
  2993. -- Run cleanup
  2994. EXEC net_find_cleanup @contextID
  2995. RETURN 0
  2996. errorLabel:
  2997. RAISERROR (@error, 16, 1, @context)
  2998. RETURN 1
  2999. END -- net_find_businessEntity_relatedBusinesses
  3000. GO
  3001. -- =============================================
  3002. -- Section: Miscellaneous
  3003. -- =============================================
  3004. -- =============================================
  3005. -- Name: net_businessEntity_owner_update
  3006. -- =============================================
  3007. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_businessEntity_owner_update' AND type = 'P')
  3008. DROP PROCEDURE net_businessEntity_owner_update
  3009. GO
  3010. CREATE PROCEDURE net_businessEntity_owner_update
  3011. @businessKey uniqueidentifier,
  3012. @PUID nvarchar(450)
  3013. WITH ENCRYPTION
  3014. AS
  3015. BEGIN
  3016. DECLARE
  3017. @error int,
  3018. @context nvarchar(4000),
  3019. @businessID bigint,
  3020. @publisherID bigint
  3021. -- Validate parameters
  3022. SET @businessID = dbo.businessID(@businessKey)
  3023. IF @businessID IS NULL
  3024. BEGIN
  3025. SET @error = 60210 -- E_invalidKeyPassed
  3026. SET @context = 'businessKey = ' + dbo.UUIDSTR(@businessKey)
  3027. GOTO errorLabel
  3028. END
  3029. SET @publisherID = dbo.publisherID(@PUID)
  3030. IF @publisherID IS NULL
  3031. BEGIN
  3032. SET @error = 60150 -- E_unknownUser
  3033. SET @context = 'PUID = ' + @PUID
  3034. GOTO errorLabel
  3035. END
  3036. UPDATE
  3037. [UDC_businessEntities]
  3038. SET
  3039. [publisherID] = @publisherID
  3040. WHERE
  3041. ([businessID] = @businessID)
  3042. RETURN 0
  3043. errorLabel:
  3044. RAISERROR (@error, 16, 1, @context)
  3045. RETURN 1
  3046. END -- net_businessEntity_owner_update
  3047. GO