Mark Yudkin
9/10/2007 6:07:00 PM
The OUTPUT clause in SQL2005 has absolutely nothing whatsoever to do with
retrieving data into an application. It is used to capture results into
another TABLE. To retrieve that information you can use a normal SELECT.
I suspect that what you actually want is to obtain the value of an IDENTITY
column, although you didn't say so. To do this, retrieve the result of
SELECT @@IDENTITY.
And finally, use ? parameter markers instead of creating code that is
demanding the launch of an SQL injection attack to cause havoc and
corruption.
"Lovely Angel For You" <lovely_angel_for_you@yahoo.com> wrote in message
news:1189315824.378122.20450@k79g2000hse.googlegroups.com...
> Hi,
>
> I am using Visual basic 6 with SQL 2005. In one particular query, I
> need to update 3 different tables, dependent on input.
>
> So, the Primary ID for FirstTable, need to be refernced in other Two
> Tables.
>
> I searched a bit on the internet and found that SQL2005, has Output
> Clause. However I am not sure how to bring the Inserted.ID to
> VisualBasic 6 variable.
>
> My Query is:
>
> StrSQL = StrSQL & "INSERT INTO People (username, phone, city)
> OutPut Inserted.ID AS CURID VALUES ("
> StrSQL = StrSQL & "'" & LCase$(UserName.Text) & "', "
> StrSQL = StrSQL & "'" & LCase$(phone.Text) & "', "
> StrSQL = StrSQL & "'" & LCase$(city.Text) & "')"
> CONN.Execute StrSQL
> CONN.Close
>
> Now how to get Inserted.ID to Visual Basic Variable. So the following
> can be executed
>
> VBVariable = Inserted.ID
>
> If city.text = "MyCity" Then
> StrSQL = StrSQL & "INSERT INTO Table2 (peopleid, zip, country)
> VALUES ("
> StrSQL = StrSQL & " & VBVariable & ", "
> StrSQL = StrSQL & "'" & LCase$(zip.Text) & "', "
> StrSQL = StrSQL & "'" & LCase$(country.Text) & "')"
> CONN.Execute StrSQL
> CONN.Close
> End If
>
> Any info on that will be highly appreciated.
>
> Best Wishes
> Lovely
>
> ________________________________________________________________________________
>
> Posted In multiple groups as the issue is about two different
> developement softwares.
>