Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Need Help with Triggers` Expand / Collapse
Author
Message
Posted Wednesday, January 22, 2014 3:15 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:22 AM
Points: 13,447, Visits: 12,310

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)
Post #1533863
Posted Wednesday, January 22, 2014 3:25 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 7:30 AM
Points: 26, 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


  Post Attachments 
Sample1.txt (3 views, 83.34 KB)
Sample2.txt (2 views, 8.01 KB)
Sample3.txt (2 views, 186.04 KB)
Post #1533869
Posted Wednesday, January 22, 2014 3:47 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:22 AM
Points: 13,447, Visits: 12,310
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)
Post #1533876
Posted Wednesday, January 22, 2014 5:50 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 7:30 AM
Points: 26, 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
Post #1533888
Posted Thursday, January 23, 2014 7:35 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:22 AM
Points: 13,447, Visits: 12,310
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)
Post #1534080
Posted Thursday, January 23, 2014 7:40 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 7:30 AM
Points: 26, 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
Post #1534084
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse