{"id":647,"date":"2014-05-20T19:17:56","date_gmt":"2014-05-20T19:17:56","guid":{"rendered":"http:\/\/blackbirdsolutions.com\/?p=647"},"modified":"2014-10-28T19:18:52","modified_gmt":"2014-10-28T19:18:52","slug":"getting-a-unique-id-in-cps","status":"publish","type":"post","link":"https:\/\/blackbirdsolutions.com\/?p=647","title":{"rendered":"Getting a Unique ID in CPS"},"content":{"rendered":"<p>In certain instances, you may find that theere is a defect in LinkLogic, or you may have another reason for doing this, but for what it&#8217;s worth, there may come a time when you need to insert a row into a Centricity database that has a unique ID field.<\/p>\n<p>There is a built-in stored procedure that performs the task, but it takes an input parameter, which can make it tricky to call. You can either create a wrapper function for the procedure that declares an input parameter and returns the value or you can copy the code and remove the params altogether.<\/p>\n<p>I have taken the second approach so that you can see the logic of the full procedure.<\/p>\n<pre>\/****** Object:  StoredProcedure [dbo].[CUSTOMgetUniqueEMRID]    Script Date: 05\/05\/2013 23:05:12 ******\/\r\nSET ANSI_NULLS ON\r\nGO\r\nSET QUOTED_IDENTIFIER ON\r\nGO\r\n-- CUSTOM_getUniqueEMRID\r\n-- returns a generated emrid as numeric(19,0)\r\n-- NOTE: dependent on emridcontrol table being setup and setupEMRIDControl having been called\r\nCREATE procedure [dbo].[CUSTOM_getUniqueEMRID]\r\n\r\nas\r\nSET NOCOUNT ON\r\nbegin\r\n     declare @theID numeric(19,0)\r\n     declare @theOffset numeric(19,0)\r\n     declare @theLastID numeric(19,0), @theWSID numeric(19,0)\r\n     declare emridcontrolcursor cursor forward_only for\r\n     select lastid,wsid from dbo.emridcontrol for update of lastid\r\n     set @theID=0\r\n     set @theOffset=50000\r\n\r\nopen emridcontrolcursor\r\nfetch next from emridcontrolcursor\r\n     into @theLastID, @theWSID\r\n\r\nif @@fetch_status = 0\r\n     begin\r\n          set @theID = dbo.convert_date_to_id(getdate()) + @theWSID\r\n          if @theID &lt;=@theLastID\r\n               set @theID = @theLastID+@theOffset\r\n          update dbo.emridcontrol set LastID=@theID\r\n     end\r\nelse\r\n     RAISERROR('unable to read emridcontrol table',10,1)\r\n\r\nclose emridcontrolcursor\r\ndeallocate emridcontrolcursor\r\nselect @theID as getUniqueEMRID\r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In certain instances, you may find that theere is a defect in LinkLogic, or you may have another reason for doing this, but for what it&#8217;s worth, there may come a time when you need to insert a row into a Centricity database that has a unique ID field. There is a built-in stored procedure [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-647","post","type-post","status-publish","format-standard","hentry","category-superuser"],"_links":{"self":[{"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=\/wp\/v2\/posts\/647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=647"}],"version-history":[{"count":1,"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=\/wp\/v2\/posts\/647\/revisions"}],"predecessor-version":[{"id":648,"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=\/wp\/v2\/posts\/647\/revisions\/648"}],"wp:attachment":[{"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blackbirdsolutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}