如何在sql Server即席查询中使用范围标识?

时间:2017-06-16 16:05:38

标签: asp.net sql-server

我在表中有一个主键Admission_ID,插入后我想从表中获取admission_Id并分配到另一个变量,我想使用范围标识来执行此操作。我也附上了查询。请仔细研究,任何帮助都将受到高度赞赏。

"Insert into Admissions(Admission_date,Student_name,Father_name,Mother_name,DOB,Gender,Address,State, City,Pincode,Admission_for,Previous_school,Fees)values('"+txtAdmDate.Text+"','"+txtStudentName+"','"+txtFatherName+"','"+txtMotherName+"',"+dateTimePicker1.Value+",'"+ gender+"','"+ txtAddress+"','"+txtState+"','"+txtCity+"','"+txtPincode+"','"+cmbClass.Text+"','"+txtPreviousSchool+"','"+txtFees+"')";

1 个答案:

答案 0 :(得分:1)

INSERT INTO <> 
Declare @Admission_ID = SCOPE_IDENTITY();
INSERT INTO <next table>