Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need Help with Triggers`


Need Help with Triggers`

Author
Message
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16582 Visits: 17024

Here are the other 2 tables


You need to test the code you post. The idea here is for me to be able to recreate your tables on my system. This has lots of errors.

I removed all the foreign keys and it will at least create the tables.


CREATE TABLE [dbo].[proposals](
[UniqueID] [int] IDENTITY(1000,1) NOT NULL,
[PropID] [int] NOT NULL,
[Rev] [int] NOT NULL,
[FRID] [int] NOT NULL,
[NatFRID] [int] NOT NULL,
[us] [bit] NOT NULL,
[ActiveRev] [bit] NOT NULL,
[COID] [int] NOT NULL,
[BillToCOID] [int] NOT NULL,
[CPID] [int] NOT NULL,
[LeadID] [int] NOT NULL,
[ProjID] [int] NOT NULL,
[LgID] [int] NOT NULL,
[SalesEng] [int] NOT NULL,
[title] [nvarchar](100) NOT NULL,
[status] [int] NOT NULL,
[created] [datetime] NOT NULL,
[resolution] [int] NOT NULL,
[resolutiondt] [date] NULL,
[resolvedby] [int] NOT NULL,
[PMappDt] [date] NULL,
[PMappLgID] [int] NOT NULL,
[CustAppDt] [date] NULL,
[CustAppLgID] [int] NOT NULL,
[CustAppCPID] [int] NOT NULL,
[FinAppDt] [datetime] NULL,
[FinAppLgID] [int] NOT NULL,
[SalesTax] [int] NOT NULL,
[CustPO] [nvarchar](50) NULL,
[PricingMethod] [int] NOT NULL,
[TaxMethod] [tinyint] NOT NULL,
[PaymentTerms] [int] NOT NULL,
[TermsConds] [int] NOT NULL,
[PCClevel] [int] NOT NULL,
[ProjCloseDt] [date] NULL,
[ProjCompDt] [date] NULL,
[SpecConds] [int] NOT NULL,
[ProjContact] [int] NOT NULL,
[MasterPermit] [nvarchar](50) NULL,
[ElectricPermit] [nvarchar](50) NULL,
[folio] [nvarchar](100) NULL,
[legal] [nvarchar](1000) NULL,
[OneTime] [decimal](10, 2) NULL,
[AdjRsn] [int] NOT NULL,
[dirtyPrice] [bit] NOT NULL,
[recentPrice] [decimal](10, 2) NULL,
[recentPandM] [decimal](10, 2) NULL,
[recentLabor] [decimal](10, 2) NULL,
[recentOther] [decimal](10, 2) NULL,
[ptDetail] [nvarchar](1000) NULL,
[isTemplate] [bit] NOT NULL,
[SysList] [nvarchar](100) NULL,
[rollups] [char](14) NOT NULL,
[prefs] [nvarchar](50) NULL,
[template] [int] NOT NULL,
[message] [nvarchar](100) NULL,
[POnotes] [nvarchar](1000) NULL,
CONSTRAINT [PK_proposals] PRIMARY KEY CLUSTERED
(
[UniqueID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UK_proposals] UNIQUE NONCLUSTERED
(
[PropID] ASC,
[Rev] ASC,
[FRID] 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].[logins](
[LgID] [int] IDENTITY(1,1) NOT NULL,
[FRID] [int] NOT NULL,
[BRID] [int] NOT NULL,
[firstname] [nvarchar](60) NOT NULL,
[lastname] [nvarchar](60) NOT NULL,
[jobtitle] [nvarchar](50) NOT NULL,
[email] [nvarchar](128) NOT NULL,
[office] [nvarchar](50) NOT NULL,
[cellphone] [nvarchar](50) NOT NULL,
[hidecell] [bit] NOT NULL,
[noDirectory] [bit] NOT NULL,
[username] [nvarchar](128) NOT NULL,
[password] [nvarchar](128) NOT NULL,
[admin] [tinyint] NOT NULL,
[owner] [bit] NOT NULL,
[lockoutct1] [tinyint] NOT NULL,
[lockoutct2] [tinyint] NOT NULL,
[remlogin] [bit] NOT NULL,
[inactive] [bit] NOT NULL,
[appLimit] [int] NOT NULL,
[svcLimit] [int] NOT NULL,
[PropPrefs] [nvarchar](50) NULL,
[coRollups] [char](14) NULL,
[propMessage] [nvarchar](100) NULL,
[dailyemail] [nvarchar](128) NULL,
[FwdEmail] [int] NOT NULL,
[mustChgPW] [bit] NOT NULL,
[BBtoken] [nvarchar](50) NULL,
[mailBox] [bit] NOT NULL,
[statusDt] [datetime] NULL,
[status] [nvarchar](100) NULL,
[helpdesk] [bit] NOT NULL,
[birthmonth] [tinyint] NOT NULL,
[birthday] [tinyint] NOT NULL,
[HomePhone] [nvarchar](50) NULL,
[HomeAdd] [nvarchar](300) NULL,
[PayPeriod] [tinyint] NOT NULL,
[ComDeal] [int] NOT NULL,
[OvrDeal] [int] NOT NULL,
[BoxDeal] [int] NOT NULL,
[BoxOvr] [int] NOT NULL,
[SvcDeal] [int] NOT NULL,
[SvcOvr] [int] NOT NULL,
[Exempt] [bit] NOT NULL,
[Boss] [int] NOT NULL,
[EmpNo] [nvarchar](50) NULL,
[Rate] [decimal](8, 2) NOT NULL,
[HWM] [tinyint] NOT NULL,
[HireDate] [datetime] NULL,
[LastRev] [datetime] NULL,
[NextRev] [datetime] NULL,
[lastView] [int] NOT NULL,
[lastFilterType] [tinyint] NOT NULL,
[lastFilterRec] [int] NOT NULL,
[ipaddress] [nvarchar](24) NULL,
CONSTRAINT [PK_logins] PRIMARY KEY CLUSTERED
(
[LgID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UK_logins_username] UNIQUE NONCLUSTERED
(
[username] 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].[ProposalProfitSplitWorksheet](
[WorksheetID] [int] IDENTITY(1,1) NOT NULL,
[DateTimeCreated] [datetime] NOT NULL,
[CreatedByUserID] [int] NOT NULL,
[CreatedByImpersonatingUserID] [int] NULL,
[ProposalUniqueID] [int] NOT NULL,
[ScenarioNumber] [int] NOT NULL,
[BillingBranchID] [int] NOT NULL,
[SiteSurveyBranchID] [int] NOT NULL,
[DateTimeAcceptedBySellingBranch] [datetime] NULL,
[AcceptedBySellingBranchUserID] [int] NULL,
[AcceptedBySellingBranchImpersonatingUserID] [int] NULL,
[DateTimeAcceptedByInstallingBranch] [datetime] NULL,
[AcceptedByInstallingBranchUserID] [int] NULL,
[AcceptedByInstallingBranchImpersonatingUserID] [int] NULL,
CONSTRAINT [PK_ProposalProfitSplitWorksheet] PRIMARY KEY CLUSTERED
(
[WorksheetID] 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




So now we have the tables. We still need a few rows of sample to do much here. If I understand correctly you want to make sure you have row in both proposals and logins with a matching FRID? Is there some way to know which row(s) in that table you are interested in? Maybe also LgID must match? I am not quite sure what the business rule is here.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Dieselbf2
Dieselbf2
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 33
So now we have the tables. We still need a few rows of sample to do much here. If I understand correctly you want to make sure you have row in both proposals and logins with a matching FRID? Is there some way to know which row(s) in that table you are interested in? Maybe also LgID must match? I am not quite sure what the business rule is here.

[/quote]

Just uploaded some sample data
Attachments
Sample1.txt (5 views, 83.00 KB)
Sample2.txt (3 views, 8.00 KB)
Sample3.txt (3 views, 186.00 KB)
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16582 Visits: 17024
Dieselbf2 (1/22/2014)
So now we have the tables. We still need a few rows of sample to do much here. If I understand correctly you want to make sure you have row in both proposals and logins with a matching FRID? Is there some way to know which row(s) in that table you are interested in? Maybe also LgID must match? I am not quite sure what the business rule is here.



Just uploaded some sample data[/quote]

OK cool. I am out of here for now. If I can't get back to this later tonight I will follow up in the morning.

Still need to know what the business rules are. What is your intention for this trigger?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Dieselbf2
Dieselbf2
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 33
Sean Lange (1/22/2014)
Dieselbf2 (1/22/2014)
So now we have the tables. We still need a few rows of sample to do much here. If I understand correctly you want to make sure you have row in both proposals and logins with a matching FRID? Is there some way to know which row(s) in that table you are interested in? Maybe also LgID must match? I am not quite sure what the business rule is here.



Just uploaded some sample data


OK cool. I am out of here for now. If I can't get back to this later tonight I will follow up in the morning.

Still need to know what the business rules are. What is your intention for this trigger?[/quote]


I need the trigger to check the logins table and what ever the Frid for the specfic LgID is, The trigger has to make sure that the same FRID is inthe proposals table for that record that will be getting inserted into the Profit table
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16582 Visits: 17024
Your sample data won't load. The last row for logins is invalid, not a huge deal I just skipped it.

However, the rows for [ProposalProfitSplitWorksheet] all fail the foreign key constraint for logins. I really need you to test your inserts. Keep in mind that we are all volunteers around here and all the time I spend messing around with being forced to turn identity insert on and off so I can insert identity values and messing around with poorly formed data and syntax is all eating into the time that I can spend on your actual issue.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Dieselbf2
Dieselbf2
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 33
Sean Lange (1/23/2014)
Your sample data won't load. The last row for logins is invalid, not a huge deal I just skipped it.

However, the rows for [ProposalProfitSplitWorksheet] all fail the foreign key constraint for logins. I really need you to test your inserts. Keep in mind that we are all volunteers around here and all the time I spend messing around with being forced to turn identity insert on and off so I can insert identity values and messing around with poorly formed data and syntax is all eating into the time that I can spend on your actual issue.



I will keep that in mind for now on. I really do appreciate everything that you are doing for me. I am new with writing triggers and the higher level thing in Tsql.

Thanks again
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search