-1

I have this trigger - can you fix error please in this code?

INSERT INTO trSMSPoolHeader (SMSGatewayServiceCode, IsSent, SendDate, CreatedDate,
                             LastUpdatedDate, CompanyCode, StoreTypeCode, MessageResponseID,
                             IsCommonMessageText, IsBusy, MessageReasonCode, SMSForCustomerRelationshipID, IsMail, MessageSubject)
    SELECT
        , IsSent = 0                     
        , SendDate = GETDATE()
        , CompanyCode = 1           
        , StoreTypeCode = 5         
        , MessageResponseID = N''                                                       
        , IsCommonMessageText = 0                     
        , IsBusy = 0                                    
        , MessageReasonCode = 4 
        , SMSForCustomerRelationshipID = N''
        , SMSGatewayServiceCode = N'AjansIletisim'
        , CreatedDate = GETDATE()
        , LastUpdatedDate = GETDATE()
        , IsMail = 0                               
        , MessageSubject = N'Kampanya' 
    FROM 
        #SendSms
    WHERE 
        PhoneNumberForSMS <> ''  
        AND DiscountOfferCode = N'Taahhüt-01'

SQL error:

Conversion failed when converting the varchar value '2020-11-26' to data type bit

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
a.b
  • 15
  • 1
  • 7
  • 2
    To answer your question you should add table structures with datatypes and add your DBMS tag despite the fact it can be guessed. – astentx Nov 26 '20 at 19:40

2 Answers2

0
  1. the order of columns in your insert statement should match with order of columns in your select statement
  2. either you are using the values from #SendSms table into trSMSPoolHeader or the hard coded values. right now you are selecting from temp table but inserting hard coded values, of course It works but It's not right way to do it .
eshirvana
  • 23,227
  • 3
  • 22
  • 38
0

This trigger tries to insert datetime type values into the fields with type bit. Most likely this is these fields judging by their names: ,CreatedDate=GETDATE() ,LastUpdatedDate=GETDATE()

Fields in the table: MessageReasonCode, SMSForCustomerRelationshipID

dzhukov
  • 383
  • 3
  • 11