ฉันมีเพิ่มเข้าไปสืบค้นอยู่ที่ไหนดั้งเดิมค่าของ Manager_ID สนามเป็น varchar(250)ค่า=31.0. ฉันต้องการจะแปลงหรือแสดงค่าที่จะแสดงเพียง'31'และเอาทุกอย่างหลังจากที่ทศนิยม. ฉันพยายามทั้งสองแปลง&แสดงให้ทั้งคู่เป็นจำนวนเต็มหรือ nvarchar,ไม่เคยประสบความสำเร็จ ฉันกำลังตามข้อผิดพลาดคือ:
การแปลงล้มเหลวเมื่อการเปลี่ยนแปลง varchar ค่า'31.0'เพื่อข้อมูลประเภทน int ได้.
ฉันต้องเล่นกับที่ต่างออกสนามประเภทโดยไม่มีความสำเร็จทั้งสองในการแทรกโต๊ะและข้อมูลของโต๊ะ
ฉันพลาดอะไรไป
ขอบคุณ
เกิดข้อผิดพลาด MSG สำหรับแปลงเป็น(int,แปลงเป็น(ทศนิยม(9,2),[Manager_ID]))
เกิดข้อผิดพลาดในการเปลี่ยนข้อมูลประเภท varchar จะ numeric.
INSERT IGNORE INTO [dbo].[tblUsers]
( [User_ID]
,[FirstName]
,[LastName]
,[FullName]
,[EMail]
,[UserRoles]
,[PostionType]
,[ManagerID]
,[UUID]
,[External_UUID]
,[home_Location_id]
,[Home_Organization_ID]
,[Record_types]
,[Location_Ceiling_ID]
,[Organization_Ceiling_ID]
,[Payroll_Identifier]
,[Created_Date]
,[Created_Time]
,[Update_Date]
,[Update_Time])
Select id-- User_ID
,first_name
,last_name
,full_name
,email
,role_id --UserRoles
,position --PositionType
,**cast(Manager_id as nvarchar(10)) as ManagerID**
,uuid
,external_uuid
,home_location_id
,home_organization_id
,[type] --Record_Types
,location_ceiling_id
,organization_ceiling_id
,payroll_identifier
,Left(Convert(varchar(20), created_at, 120),10) as Create_Date
,Right(convert(varchar(16), created_at, 120),5) as Create_Time
,left(Convert(varchar(20), updated_at, 120),10) as Update_Date
,Right(convert(varchar(16), updated_at, 120),5) as Update_Time
from [stg].[Users]
สุดท้ายทางออก
,SUBSTRING(manager_id, 1,
CASE WHEN CHARINDEX('.',manager_id) - 1 < 0
THEN LEN(manager_id)
ELSE CHARINDEX('.',manager_id) - 1 END) as ManagerID