Insert 100 records in a table [Resolved]

Posted by Sudhakar_A under Sql Server on 11/1/2013 | Points: 10 | Views : 1807 | Status : [Member] | Replies : 2
I to insert 100 records in a table. E.g. If the table emp is there and I want to insert emp_name as emp1, emp2, .. emp100 in that table. Can any one help me.




Responses

Posted by: Allemahesh on: 11/1/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
You can try the below code:-

DECLARE @COUNT AS INT = 1


WHILE @COUNT < 101
BEGIN
DECLARE @EmpName as varchar(16)
SET @EmpName = 'emp' + CAST (@COUNT AS VARCHAR(100))

INSERT INTO Emp(emp_name)values (@EmpName)

SET @COUNT = @COUNT + 1
END


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/1/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
alternate solution is
1) prepare data in excel ( in A column just type emp1, emp2, and drag the rows up to 100 )
2) in the B column type as follows

=concatenate( "insert into tablename (empnameCol) values('", A1,"');")


and drag this B column upto 100 rows
3) just copy these insert script and run it in sql server management(SSMS)

In this we database developers will prepare master/sample data


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response