Usage:
1. varchar type -----> int
For example, if the database table has the ID (INT) and name (varchar (10) columns, you want to output the value of ID + name:
Select *, convert (varchar, ID) + name from table_3;
Or select *, convert (varchar (10), ID) + name from table_3;
2. Convert (varchar (8), getdate (), 112) indicates the output of 20120808 characters
Instance: Add a growth issue number to the database table, and generate a self-growth issue number for the current day based on different law enforcement officers.
Question No.: By Time + userid + id = 2012080200101
-- Set the first data id value of the day to 2012080800001 set @ temp_pid = convert (varchar (8), getdate (), 112) + @ in_police + '01 '; -- obtain the total number of reported problems of this executor. Select @ temp3 = count (*) from problem where police = @ in_police; If (@ temp3 <1) set @ temp1 = 0; elsebegin -- Obtain the question number of the last reported problem from the law enforcement officer. Select @ temp1 = max (PID) from problem where police = @ in_police; end -- question number + + If (@ temp_pid> @ temp1) set @ pid = @ temp_pid; else begin set @ pid = substring (@ temp1,) + 1; if (@ PID/10 = 0) set @ pid = convert (varchar (8), getdate (), 112) + @ in_police + '0' + @ PID; else set @ pid = convert (varchar (8), getdate (), 112) + @ in_police + @ PID; endbegin try insert into problem values (@ PID, @ in_maintype, @ in_subtype, @ in_carid, @ response, @ in_driver, @ in_coordinate, @ response, @ in_fare, @ response, @ in_police, @ in_status, @ in_datetime); Set @ out_parameter = 0; end trybegin catchset @ out_parameter = 2; end catch
Note:
This stored procedure is intended to insert a new problematic data.