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


Concatenate IN TRIGGER two fields into one in this line of the TRIGGER T-SQL?:


Concatenate IN TRIGGER two fields into one in this line of the TRIGGER T-SQL?:

Author
Message
briancampbellmcad
briancampbellmcad
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 403
Can anyone show how to concatenate two fields into one in this line of the TRIGGER T-SQL?:

INSERTED.(HeatTicketNumber,PO_Number)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trPopulateJournalEntries]
ON [dbo].[tblTransactions]
AFTER INSERT
AS
BEGIN
IF (SELECT Transaction_Type FROM INSERTED) = 'From Bulk Assignment'
INSERT INTO tblSWJournal
(tblSWJournal.Ledger,
tblBulkPurchases.Amt)
SELECT
INSERTED.(HeatTicketNumber,PO_Number)
INSERTED.Unit_Price
FROM INSERTED
END
GO
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
it would be simple concatenation;
if the types happen to be integers, you might need to convert them to varchars:

INSERT INTO tblSWJournal
(tblSWJournal.Ledger,
tblBulkPurchases.Amt)
SELECT
CONVERT(varchar(30),INSERTED.HeatTicketNumber)
+ ':'
+ CONVERT(VARCHAR(30),INSERTED.PO_Number),
INSERTED.Unit_Price
FROM INSERTED



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

briancampbellmcad
briancampbellmcad
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 403
In general it seems to not like something else that keeps popping up:

Msg 102, Level 15, State 1, Procedure trPopulateJournalEntries, Line 11
Incorrect syntax near '('.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
looked a little deeper, this is a syntactically correct version that only inserts the rows that have INSERTED.Transaction_Type = 'From Bulk Assignment'


GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trPopulateJournalEntries]
ON [dbo].[tblTransactions]
AFTER INSERT
AS
BEGIN
INSERT INTO tblSWJournal
(tblSWJournal.Ledger,tblBulkPurchases.Amt)
SELECT
CONVERT(VARCHAR(30), INSERTED.HeatTicketNumber) + ':' + CONVERT(VARCHAR(30), INSERTED.PO_Number),
INSERTED.Unit_Price
FROM INSERTED
WHERE INSERTED.Transaction_Type = 'From Bulk Assignment'
END
GO




Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

briancampbellmcad
briancampbellmcad
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 403
Both the PO_Number and HeatTicketNumber are already Varchar as the table datatype... so (?) no need for conversion (?)...

I ran the code above and now have a SQL error popping up from my ASp.net app:

String or binary data would be truncated.
The statement has been terminated.
Tava
Tava
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 774
briancampbellmcad (11/12/2012)
Both the PO_Number and HeatTicketNumber are already Varchar as the table datatype... so (?) no need for conversion (?)...

I ran the code above and now have a SQL error popping up from my ASp.net app:

String or binary data would be truncated.
The statement has been terminated.


Check the datatype size of the VARCHAR columns compared to the PO_Number & HeatTicketNumber? Chances are one of those 2 columns is greater in length then what you have specified. That's what the error you got normally means?
Tava
Tava
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 774
Tava (11/12/2012)
briancampbellmcad (11/12/2012)
Both the PO_Number and HeatTicketNumber are already Varchar as the table datatype... so (?) no need for conversion (?)...

I ran the code above and now have a SQL error popping up from my ASp.net app:

String or binary data would be truncated.
The statement has been terminated.


Check the datatype size of the VARCHAR columns compared to the PO_Number & HeatTicketNumber? Chances are one of those 2 columns is greater in length then what you have specified. That's what the error you got normally means?



Thought i would help you as I don't know you're exact skill level. Do a Length check on your data.



SELECT
LEN(ColumnName) AS StringLength
FROM
TableName
ORDER BY
StringLength DESC




What ever the biggest size it is needs to be less than the specified size on the VARCHAR(X)
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
Tava (11/12/2012)
briancampbellmcad (11/12/2012)
Both the PO_Number and HeatTicketNumber are already Varchar as the table datatype... so (?) no need for conversion (?)...

I ran the code above and now have a SQL error popping up from my ASp.net app:

String or binary data would be truncated.
The statement has been terminated.


Check the datatype size of the VARCHAR columns compared to the PO_Number & HeatTicketNumber? Chances are one of those 2 columns is greater in length then what you have specified. That's what the error you got normally means?



I agree; the size of the field tblSWJournal.Ledger has to be at least as large as the maximum size of PO_Number & HeatTicketNumber & the separator ':'

in my example, that would be 61 characters (two varchar(30)'s plus the semicolon); you know what your real field sizes are; you'll need to change the tblSWJournal.Ledger size most likely.

review your data sized and fix whatever is invalid.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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