Get records for purchase tracking and categorize them

hi

i tried to run your script ... giving errors ...please check :slight_smile: :slight_smile:

create data script ... ahmeda gave
CREATE TABLE [dbo].[accesscodes] 
  ( 
     [id]              [INT] IDENTITY(1, 1) NOT NULL, 
     [datecreated]     [DATETIME] NOT NULL, 
     [active]          [BIT] NOT NULL, 
     [accesscode]      NVARCHAR NOT NULL, 
     [activefrom]      [DATETIME] NULL, 
     [activeto]        [DATETIME] NULL, 
     [hremail]         NVARCHAR NULL, 
     [percentdiscount] [INT] NOT NULL, 
     CONSTRAINT [PK_AccessCodes] PRIMARY KEY CLUSTERED ( [id] ASC )WITH ( 
     pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = OFF, 
     allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 

go 

CREATE TABLE [dbo].[category] 
  ( 
     [categoryid]   [INT] IDENTITY(1, 1) NOT NULL, 
     [categoryname] NVARCHAR NOT NULL, 
     CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED ( [categoryid] ASC )WITH ( 
     pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = OFF, 
     allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 

go 

CREATE TABLE [dbo].[course] 
  ( 
     [courseid]                     [INT] IDENTITY(1, 1) NOT NULL, 
     [createdon]                    [DATETIME] NOT NULL, 
     [isactive]                     [BIT] NOT NULL, 
     [coursenumber]                 NVARCHAR NOT NULL, 
     [title]                        NVARCHAR NOT NULL, 
     [categoryid]                   [INT] NOT NULL, 
     [description]                  NVARCHAR NOT NULL, 
     [cost]                         [MONEY] NOT NULL, 
     [isaarcapproved]               [BIT] NOT NULL, 
     [status]                       [TINYINT] NOT NULL, 
     [providerid]                   [INT] NOT NULL, 
     [contracthours]                [DECIMAL](16, 2) NOT NULL, 
     [certificatefee]               [MONEY] NOT NULL, 
     [disclaimer]                   NVARCHAR NULL, 
     [requiresurveycompletion]      [BIT] NOT NULL, 
     [requirecertificateaccesscode] [BIT] NOT NULL, 
     CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED ( [courseid] ASC )WITH ( 
     pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = OFF, 
     allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 

go 

CREATE TABLE [dbo].[courseaccesscode] 
  ( 
     [id]           [INT] IDENTITY(1, 1) NOT NULL, 
     [courseid]     [INT] NOT NULL, 
     [accesscodeid] [INT] NOT NULL, 
     CONSTRAINT [PK_CourseAccessCode] PRIMARY KEY CLUSTERED ( [id] ASC )WITH ( 
     pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = OFF, 
     allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 

go 

CREATE TABLE [dbo].[userorderhistory] 
  ( 
     [id]                   [INT] IDENTITY(1, 1) NOT NULL, 
     [dateadded]            [DATETIME] NOT NULL, 
     [userid]               [INT] NOT NULL, 
     [orderplacedon]        [DATETIME] NOT NULL, 
     [courseid]             [INT] NOT NULL, 
     [coursetitle]          NVARCHAR NOT NULL, 
     [coursenumber]         NVARCHAR NOT NULL, 
     [totalcost]            [MONEY] NOT NULL, 
     [providerid]           [INT] NOT NULL, 
     [providername]         NVARCHAR NOT NULL, 
     [providernumber]       NVARCHAR NOT NULL, 
     [provideremail]        NVARCHAR NOT NULL, 
     [useremailaddress]     NVARCHAR NOT NULL, 
     [coursesubscriptionid] [INT] NULL, 
     CONSTRAINT [PK_UserOrderHistory] PRIMARY KEY CLUSTERED ( [id] ASC )WITH ( 
     pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = OFF, 
     allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 

go 

CREATE TABLE [dbo].[userorderhistorytransaction] 
  ( 
     [id]                    [INT] IDENTITY(1, 1) NOT NULL, 
     [createdon]             [DATETIME] NOT NULL, 
     [userid]                [INT] NOT NULL, 
     [providertransactionid] NVARCHAR NOT NULL, 
     [totalcost]             [MONEY] NOT NULL, 
     [userorderhistoryid]    [INT] NOT NULL, 
     [accesscereference]     NVARCHAR NOT NULL, 
     [accesscodeid]          [INT] NULL, 
     [authcode]              NVARCHAR NULL, 
     [reasoncode]            NVARCHAR NULL, 
     [decision]              NVARCHAR NULL, 
     [responsestring]        NVARCHAR NULL, 
     CONSTRAINT [PK_UserOrderHistoryTransaction] PRIMARY KEY CLUSTERED ( [id] 
     ASC )WITH (pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = 
     OFF, allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 
textimage_on [PRIMARY] 

go 

CREATE TABLE [dbo].[userregisteredcourses] 
  ( 
     [id]                           [INT] IDENTITY(1, 1) NOT NULL, 
     [userid]                       [INT] NOT NULL, 
     [courseid]                     [INT] NOT NULL, 
     [dateofcompletion]             [DATETIME] NULL, 
     [confirmationcode]             NVARCHAR NULL, 
     [status]                       [TINYINT] NOT NULL, 
     [affirmationsigned]            [BIT] NULL, 
     [purchasedcertificate]         [BIT] NOT NULL, 
     [coursesubscriptionexpiration] [DATETIME] NULL, 
     [coursesubscriptionid]         [INT] NULL, 
     CONSTRAINT [PK_UserRegisteredCourses] PRIMARY KEY CLUSTERED ( [id] ASC ) 
     WITH (pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = OFF, 
     allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 

go 

CREATE TABLE [dbo].[users] 
  ( 
     [userid]                  [INT] IDENTITY(1, 1) NOT NULL, 
     [dateofregistration]      [DATETIME] NOT NULL, 
     [firstname]               NVARCHAR NOT NULL, 
     [lastname]                NVARCHAR NOT NULL, 
     [password]                NVARCHAR NOT NULL, 
     [isactive]                [BIT] NOT NULL, 
     [emailaddress]            NVARCHAR NOT NULL, 
     [phonenumber]             NVARCHAR NOT NULL, 
     [registrationkey]         NVARCHAR NULL, 
     [proflicensenumber]       VARCHAR NULL, 
     [aarc]                    VARCHAR NULL, 
     [state]                   VARCHAR NULL, 
     [securityquestion]        NVARCHAR NULL, 
     [securityquestionanswer]  NVARCHAR NULL, 
     [newslettersub]           [BIT] NOT NULL, 
     [professionallicensetype] [INT] NOT NULL, 
     CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED ( [userid] ASC )WITH (pad_index 
     = OFF, statistics_norecompute = OFF, ignore_dup_key = OFF, allow_row_locks 
     = on, allow_page_locks = on) ON [PRIMARY] 
  ) 
ON [PRIMARY] 

go 

ALTER TABLE [dbo].[accesscodes] 
  ADD CONSTRAINT [DF_AccessCodes_DateCreated] DEFAULT (Getdate()) FOR 
  [DateCreated] 

go 

ALTER TABLE [dbo].[accesscodes] 
  ADD CONSTRAINT [DF_AccessCodes_Active] DEFAULT ((1)) FOR [Active] 

go 

ALTER TABLE [dbo].[accesscodes] 
  ADD CONSTRAINT [DF_AccessCodes_PercentDiscount] DEFAULT ((0)) FOR 
  [PercentDiscount] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_CreatedOn] DEFAULT (Getdate()) FOR [CreatedOn] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_IsActive] DEFAULT ((0)) FOR [IsActive] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_Cost] DEFAULT ((0)) FOR [Cost] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_IsAARCApproved] DEFAULT ((0)) FOR [IsAARCApproved] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_Status] DEFAULT ((0)) FOR [Status] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_ContactHours] DEFAULT ((0)) FOR [ContractHours] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_CertificateFee] DEFAULT ((0)) FOR [CertificateFee] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_RequireSurveyCompletion] DEFAULT ((0)) FOR 
  [RequireSurveyCompletion] 

go 

ALTER TABLE [dbo].[course] 
  ADD CONSTRAINT [DF_Course_RequireCertificateAccessCode] DEFAULT ((0)) FOR 
  [RequireCertificateAccessCode] 

go 

ALTER TABLE [dbo].[userorderhistory] 
  ADD CONSTRAINT [DF_UserOrderHistory_DateAdded] DEFAULT (Getdate()) FOR 
  [DateAdded] 

go 

ALTER TABLE [dbo].[userorderhistory] 
  ADD CONSTRAINT [DF_UserOrderHistory_TotalCost] DEFAULT ((0)) FOR [TotalCost] 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  ADD CONSTRAINT [DF_UserOrderHistoryTransaction_CreatedOn] DEFAULT (Getdate()) 
  FOR [CreatedOn] 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  ADD CONSTRAINT [DF_UserOrderHistoryTransaction_TotalCost] DEFAULT ((0)) FOR 
  [TotalCost] 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  ADD CONSTRAINT [DF_UserRegisteredCourses_Status] DEFAULT ((0)) FOR [Status] 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  ADD DEFAULT ((0)) FOR [AffirmationSigned] 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  ADD CONSTRAINT [DF_UserRegisteredCourses_PurchasedCertificate] DEFAULT ((0)) 
  FOR [PurchasedCertificate] 

go 

ALTER TABLE [dbo].[users] 
  ADD CONSTRAINT [DF_Users_DateOfRegistration] DEFAULT (Getdate()) FOR 
  [DateOfRegistration] 

go 

ALTER TABLE [dbo].[users] 
  ADD CONSTRAINT [DF_Users_IsActive] DEFAULT ((0)) FOR [IsActive] 

go 

ALTER TABLE [dbo].[users] 
  ADD CONSTRAINT [DF_Users_NewsletterSub] DEFAULT ((1)) FOR [NewsletterSub] 

go 

ALTER TABLE [dbo].[course] 
  WITH CHECK ADD CONSTRAINT [FK_Course_Category] FOREIGN KEY([categoryid]) 
  REFERENCES [dbo].[category] ([categoryid]) 

go 

ALTER TABLE [dbo].[course] 
  CHECK CONSTRAINT [FK_Course_Category] 

go 

ALTER TABLE [dbo].[course] 
  WITH CHECK ADD CONSTRAINT [FK_Course_Provider] FOREIGN KEY([providerid]) 
  REFERENCES [dbo].[provider] ([id]) 

go 

ALTER TABLE [dbo].[course] 
  CHECK CONSTRAINT [FK_Course_Provider] 

go 

ALTER TABLE [dbo].[courseaccesscode] 
  WITH CHECK ADD CONSTRAINT [FK_CourseAccessCode_AccessCodes] FOREIGN KEY( 
  [accesscodeid]) REFERENCES [dbo].[accesscodes] ([id]) 

go 

ALTER TABLE [dbo].[courseaccesscode] 
  CHECK CONSTRAINT [FK_CourseAccessCode_AccessCodes] 

go 

ALTER TABLE [dbo].[courseaccesscode] 
  WITH CHECK ADD CONSTRAINT [FK_CourseAccessCode_Course] FOREIGN KEY([courseid]) 
  REFERENCES [dbo].[course] ([courseid]) 

go 

ALTER TABLE [dbo].[courseaccesscode] 
  CHECK CONSTRAINT [FK_CourseAccessCode_Course] 

go 

ALTER TABLE [dbo].[userorderhistory] 
  WITH CHECK ADD CONSTRAINT [FK_UserOrderHistory_Users] FOREIGN KEY([userid]) 
  REFERENCES [dbo].[users] ([userid]) 

go 

ALTER TABLE [dbo].[userorderhistory] 
  CHECK CONSTRAINT [FK_UserOrderHistory_Users] 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  WITH CHECK ADD CONSTRAINT [FK_UserOrderHistoryTransaction_AccessCodes] FOREIGN 
  KEY([accesscodeid]) REFERENCES [dbo].[accesscodes] ([id]) 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  CHECK CONSTRAINT [FK_UserOrderHistoryTransaction_AccessCodes] 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  WITH CHECK ADD CONSTRAINT [FK_UserOrderHistoryTransaction_UserOrderHistory] 
  FOREIGN KEY([userorderhistoryid]) REFERENCES [dbo].[userorderhistory] ([id]) 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  CHECK CONSTRAINT [FK_UserOrderHistoryTransaction_UserOrderHistory] 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  WITH CHECK ADD CONSTRAINT [FK_UserOrderHistoryTransaction_Users] FOREIGN KEY( 
  [userid]) REFERENCES [dbo].[users] ([userid]) 

go 

ALTER TABLE [dbo].[userorderhistorytransaction] 
  CHECK CONSTRAINT [FK_UserOrderHistoryTransaction_Users] 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  WITH CHECK ADD CONSTRAINT [FK_UserRegisteredCourses_Course] FOREIGN KEY( 
  [courseid]) REFERENCES [dbo].[course] ([courseid]) 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  CHECK CONSTRAINT [FK_UserRegisteredCourses_Course] 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  WITH CHECK ADD CONSTRAINT [FK_UserRegisteredCourses_CourseSubscription] 
  FOREIGN KEY([coursesubscriptionid]) REFERENCES [dbo].[coursesubscription] ( 
  [id]) 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  CHECK CONSTRAINT [FK_UserRegisteredCourses_CourseSubscription] 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  WITH CHECK ADD CONSTRAINT [FK_UserRegisteredCourses_Users] FOREIGN KEY( 
  [userid]) REFERENCES [dbo].[users] ([userid]) 

go 

ALTER TABLE [dbo].[userregisteredcourses] 
  CHECK CONSTRAINT [FK_UserRegisteredCourses_Users] 

go 

ALTER TABLE [dbo].[users] 
  WITH CHECK ADD CONSTRAINT [FK_Users_Users] FOREIGN KEY( 
  [professionallicensetype]) REFERENCES [dbo].[category] ([categoryid]) 

go 

ALTER TABLE [dbo].[users] 
  CHECK CONSTRAINT [FK_Users_Users] 

go
when i try to run ... Errors

Weird. I simply did a generate scripts and copied it here.
It's why I had the link in the first place to the bacpac file... so it's easier for everyone but no one wanted to click on the link.

Hi

I downloaded your link ..
Data.txt...Couple of days ago

It's too huge ...

It's not that big. But has all the data you need or just import the dacbac in first link.

Lets leave all that aside

How can I find you a solution ???? :slight_smile: :slight_smile:
can i remote desktop to your workstation

Unfortunately not... I have provided all information here so there is no excuse or reason to not continue :blush:

hi

i tried to import your bacpac file

un forunately i am getting error :frowning:

Ensure you are using the latest SQL Server Management studio.

I cannot install latest ssms ..don't have
Fire power and disk space to install

What i am using..

abandoning thread

1 Like

Or Albert Einstein approach..or Thomas Alva Edison approach...keep trying a million..:grin::grin: