Umair Ahmed
Umair Ahmed

Reputation: 11694

Stored procedure inside a insert statement

I am trying to generate random data for my sql server database. Ive created a stored procedure that takes length of string to be generated but the problem is that it wont allow me to call it inside the insert statement.

insert into table1 (varchar_data,int_data) value ((sp_GenerateRandomString 4),CAST(RAND() * 10 AS INT) % 6 + 1 )

also this is not working

insert into table1  (varchar_data,int_data) select ((sp_GenerateRandomString 4),CAST(RAND() * 10 AS INT) % 6 + 1 )

Upvotes: 1

Views: 2546

Answers (2)

Remus Rusanu
Remus Rusanu

Reputation: 294287

INSERT INTO ... EXEC sp_procedure

Upvotes: 0

Philippe Leybaert
Philippe Leybaert

Reputation: 171774

You should use a user defined function instead of a stored procedure. A stored procedure cannot be used in expressions, but functions can.

A good introduction can be found here: http://www.sqlteam.com/article/user-defined-functions

Upvotes: 3

Related Questions