Reputation: 3256
I have following select statement:
string query = @"Select Sudent, " + Guid.NewGuid() + " as Id, Name, DOB from Student where Name = Ken";
then i am using this statement in bulkcopy command to do an insert in table. But problem is it is generating only 1 guid for all 5 rows and throws an error. How can i get different guid for all 5 (or any number of rows select gets) rows for column Id.
Upvotes: 2
Views: 6505
Reputation: 604
string query = @"Select Student, newid() as Id, Name, DOB from Student where Name = Ken";
Upvotes: 6
Reputation: 135789
For SQL Server:
SELECT Student, NEWID() AS Id, Name, DOB
FROM Student
WHERE Name = 'Ken'
For MySQL:
SELECT Student, UUID() AS Id, Name, DOB
FROM Student
WHERE Name = 'Ken'
For Oracle:
SELECT Student, SYS_GUID() AS Id, Name, DOB
FROM Student
WHERE Name = 'Ken'
Upvotes: 5