可能重复:
在 sql server 中修剪左边的字符?
我在下面有一个查询,它从我们的数据库中获取客户信息以发送优惠券。关于邮政编码,我们只需要该字段的前 5 位数字......我怎样才能只返回前 5 位?我的代码如下:
SELECT Invoice_Tb.Customer_First_Name AS firstname, Invoice_Tb.Customer_Last_Name AS lastname, Invoice_Tb.Customer_Address AS add1, Invoice_Tb.City,
Invoice_Tb.Customer_State AS State, Invoice_Tb.ZIP_Code AS ZIP, Invoice_Tb.Customer_Email_Address AS [Email Address],
Invoice_Tb.Vehicle_Mileage AS [Vehicle Mileage], Invoice_Tb.Invoice_Date AS [Date Of Service], Invoice_Tb.Store_Number, @startdate AS Start_Date, @enddate AS End_Date
FROM Invoice_Detail_Tb INNER JOIN
Invoice_Tb ON Invoice_Detail_Tb.Invoice_Number = Invoice_Tb.Invoice_Number AND Invoice_Detail_Tb.Invoice_Date = Invoice_Tb.Invoice_Date
WHERE (Invoice_Detail_Tb.Store_Category_Code = 'FS') AND (Invoice_Tb.Invoice_Date BETWEEN CONVERT(DATETIME, @startdate, 102) AND CONVERT(Datetime,
@enddate, 102)) AND (Invoice_Tb.Reminder_Mail_Flag = 'Y')