0

Here is an example of my query. I would like to use the value created by NEWID() in the SELECT statement.

INSERT INTO myTable (a, b,c,d)
  SELECT NEWID() ,@b ,@c,CONCAT('-g ', (need NEWID() value here), ' -m ',@m,' -n ',@db) 
  AS parameter FROM VBsplit(@g,',')
  • This quetion should help you narrow down your answer: http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row – Elias Jul 24 '13 at 18:12
  • Maybe it could help you: http://www.michaelmerrell.com/2011/06/how-to-insert-the-same-newid-unique-identifier-into-multiple-columns/ – Maxim Zhukov Jul 24 '13 at 18:13

1 Answers1

2

I would do this with a subquery:

INSERT INTO myTable (a, b, c, d)
  SELECT a, @b, @c, CONCAT('-g ', a, ' -m ', @m,' -n ', @db) as parameter
  FROM (select newid() as a, v.*
        from VBsplit(@g,',') v
       ) t
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • @Joe . . . It is called a table alias. Ironically, someone else just asked this question here http://stackoverflow.com/questions/17841576/ms-sql-2008-declare-function/17841627#17841627. – Gordon Linoff Jul 24 '13 at 18:35
  • I see is it necessary in this case since it seems it is never utilized? –  Jul 24 '13 at 18:39
  • To answer My own question...yes –  Jul 24 '13 at 18:54