Sathya Sambath

Sathya Sambath

  • NA
  • 284
  • 113k

Create the Userdefine table ,Not insert the value into table

Mar 29 2018 1:42 AM
Hi,
 
I have create table and user defined the table. Please clarify the error.
 
Below the procedure,table,output and error also.
 
Table field are:
  1. Create table UpdatePatientdetails  
  2. (  
  3. PatientID int Not NULL,  
  4. FieldChange varchar(255),  
  5. NewValue varchar(255),  
  6. OldValue varchar(255),  
  7. CRDateTime datetime ,  
  8. UserName varchar(200),  
  9. )  
User Defined Table
  1. CREATE TYPE [dbo].[UpdatePatienttable8] AS TABLE(  
  2. [PatientID] [intNOT NULL,  
  3. [FieldChange] [varchar](255),  
  4. [NewValue] [varchar](255) ,  
  5. [OldValue] [varchar](255) ,  
  6. [CRDateTime] [datetime] ,  
  7. [UserName] [varchar](200)  
  8. )  
  9. GO  
Stored Procedures:
  1. ALTER PROCEDURE [dbo].[Update_PatientDetails_SP]  
  2. (  
  3. @ptype char(1) = NULL,  
  4. @UpdatePatient1 [dbo].[UpdatePatienttable8] READONLY  
  5. )  
  6. AS  
  7. IF (@ptype='UP')  
  8. BEGIN  
  9. INSERT INTO UpdatePatientdetails  
  10. (  
  11. PatientID,  
  12. FieldChange,  
  13. NewValue,  
  14. OldValue,  
  15. CRDateTime,  
  16. [UserName]  
  17. )  
  18. SELECT * FROM @UpdatePatient1  
  19. END  
  20. Execute the Procedure:  
  21. DECLARE @MyUserDTableType UpdatePatienttable8  
  22. INSERT INTO @MyUserDTableType VALUES (1, 'name','sa','ser',GETDATE(),'xxx')  
  23. INSERT INTO @MyUserDTableType VALUES (2,'name','sa','sere',GETDATE() ,'xxx')  
  24. INSERT INTO @MyUserDTableType VALUES (3, 'name','sa','sera',GETDATE(),'xx')  
  25. INSERT INTO @MyUserDTableType VALUES (4, 'fathername','sas','ser',GETDATE() ,'xxx')  
  26. EXECUTE [Update_PatientDetails_SP] @MyUserDTableType  
After execute
 
(1 row(s) affected)
(1 row(s) affected)
Msg 206, Level 16, State 2, Procedure Update_PatientDetails_SP, Line 0
Operand type clash: UpdatePatienttable8 is incompatible with char

Answers (1)