Variable like Record (in Pascal) in T-SQL  
Author Message
DurbanMom





PostPosted: Tue Feb 26 15:00:12 CST 2008 Top

SQL Server Developer >> Variable like Record (in Pascal) in T-SQL

When I FETCH from CURSOR I must create same quantity of variables as cursor output columns.
In this case it would be better to use only one variable of type Record (like in Pascal language).
Is it possible in T-SQL (on MS-SQL-server version 2005)?


For example:



DECLARE myCursor CURSOR
FOR SELECT Id, Name, DateOfBirth, eMail, ... FROM %input_table_name%;

OPEN myCursor;



...

...

END;

CLOSE myCursor;
DEALLOCATE myCursor;

SQL Server187  
 
 
Mike





PostPosted: Tue Feb 26 15:00:12 CST 2008 Top

SQL Server Developer >> Variable like Record (in Pascal) in T-SQL Hi David,

There is no equivalent - you need to explicitly reference all the columns.
But I would always ask - do you *REALLY* need that cursor? If you post what
you are trying to achieve there may be a way of doing it with no cursor,
which is easier, faster, and generally reckoned to be a good thing.

Mike John




> When I FETCH from CURSOR I must create same quantity of variables as
> cursor output columns.
> In this case it would be better to use only one variable of type Record
> (like in Pascal language).
> Is it possible in T-SQL (on MS-SQL-server version 2005)?
>
>
> For example:
>

>
> DECLARE myCursor CURSOR
> FOR SELECT Id, Name, DateOfBirth, eMail, ... FROM %input_table_name%;
>
> OPEN myCursor;
>


> ...


> ...

> END;
>
> CLOSE myCursor;
> DEALLOCATE myCursor;

 
 
David





PostPosted: Tue Feb 26 15:31:02 CST 2008 Top

SQL Server Developer >> Variable like Record (in Pascal) in T-SQL

> When I FETCH from CURSOR I must create same quantity of variables as
> cursor output columns.
> In this case it would be better to use only one variable of type Record
> (like in Pascal language).
> Is it possible in T-SQL (on MS-SQL-server version 2005)?
>
>
> For example:
>

>
> DECLARE myCursor CURSOR
> FOR SELECT Id, Name, DateOfBirth, eMail, ... FROM %input_table_name%;
>
> OPEN myCursor;
>


> ...


> ...

> END;
>
> CLOSE myCursor;
> DEALLOCATE myCursor;


Stop trying to write SQL like a Pascal programmer! The answer is that you
don't need a cursor (I'm pretty certain you don't). Now what is your
question?

--
David Portas


 
 
Trey





PostPosted: Tue Feb 26 15:36:32 CST 2008 Top

SQL Server Developer >> Variable like Record (in Pascal) in T-SQL
> When I FETCH from CURSOR I must create same quantity of variables as
> cursor output columns.
> In this case it would be better to use only one variable of type Record
> (like in Pascal language).
> Is it possible in T-SQL (on MS-SQL-server version 2005)?
>
>
> For example:
>

>
> DECLARE myCursor CURSOR
> FOR SELECT Id, Name, DateOfBirth, eMail, ... FROM %input_table_name%;
>
> OPEN myCursor;
>


> ...


> ...

> END;
>
> CLOSE myCursor;
> DEALLOCATE myCursor;

Is that print really the end action you're after? Doesn't seem
particularly useful.
What are really trying to do?
 
 
David





PostPosted: Wed Feb 27 16:09:45 CST 2008 Top

SQL Server Developer >> Variable like Record (in Pascal) in T-SQL I realy trying to do:
/--------------------------------------------------------------\
USE [jiradb]
GO






declare JobJourLine cursor
for select [No_], [Task Code], [Description], [Quantity], [Unit of Measure Code], [Starting date (attend_)]


open JobJourLine;





END

close JobJourLine;
deallocate JobJourLine;
GO
\__________________________________________________________________/

And I confesses that I am beginner in programming in T-SQL.
;-)



>> When I FETCH from CURSOR I must create same quantity of variables as
>> cursor output columns.
>> In this case it would be better to use only one variable of type
>> Record (like in Pascal language).
>> Is it possible in T-SQL (on MS-SQL-server version 2005)?
>>
>>
>> For example:
>>

>>
>> DECLARE myCursor CURSOR
>> FOR SELECT Id, Name, DateOfBirth, eMail, ... FROM %input_table_name%;
>>
>> OPEN myCursor;
>>


>> ...


>> ...

>> END;
>>
>> CLOSE myCursor;
>> DEALLOCATE myCursor;
>
> Is that print really the end action you're after? Doesn't seem
> particularly useful.
> What are really trying to do?