views:

257

answers:

2

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 )
+3  A: 

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

Philippe Leybaert
A: 

INSERT INTO ... EXEC sp_procedure

Remus Rusanu