How to get values from SELECT stmt into local variables?

mkerrigan_at_ktoys.com
Date: 02/04/05


Date: 4 Feb 2005 12:18:55 -0800

I have a table which is used for history. It has several fields, any
one of which would be "updated", but in this case, a new record is
inserted instead with a new value and effective date. The old values
in the previous record need to be inserted into the new record as well.

I am using a SELECT statement to get the values of the last record, to
insert into the new record along with the new values. I would like to
do something similar to the FETCH INTO command used by a cursor, which
would then populate the variables with the results of the SELECT
statement.

As far as I know, the only options I have are to fetch each value
separately with separate SELECT statements, or to make a cursor that
would only be used to retrieve one record.

Is there any other way to do this? Thanks!



Relevant Pages

  • Re: How to get values from SELECT stmt into local variables?
    ... declare @var1 int, @var2 int ... > do something similar to the FETCH INTO command used by a cursor, ... > As far as I know, the only options I have are to fetch each value ... > separately with separate SELECT statements, or to make a cursor that ...
    (microsoft.public.sqlserver.programming)
  • Re: Opinions on approach, please...
    ... To emulate this I plan on using an SQL cursor. ... Is it because when you FETCH from a cursor you go back to the ... therefore the cursor cannot be referred to in Positioned UPDATE and DELETE ... I just did a test and even without specifying FOR READ ONLY I was able to ...
    (comp.lang.cobol)
  • Re: Ladegeschwindigkeit eines ListViews
    ... Der Aspekt, den Du jetzt eingebracht hast, ... den cursor, mit der Zeilennumer als key, aus dem resultset holen? ... FETCH ABSOLUTE 2 FROM myCursor ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Ladegeschwindigkeit eines ListViews
    ... den cursor, mit der Zeilennumer als key, aus dem resultset holen? ... FETCH ABSOLUTE 2 FROM myCursor ... ja mal ein neuer Aspekt hinzu, ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: number of rows in cursor
    ... DECLARE authors_cursor insensitive CURSOR FOR( ... declare @l sysname ... FETCH NEXT FROM authors_cursor into @l ...
    (microsoft.public.sqlserver.programming)