Table Variables

Sql'de saklı yordamlar ile çalışırken saklı yordam içinde dinamik t-sql bir değer döndürüyorsanız ve bu sp'yi entity framework 4.0 ile kullanıyorsanız "The selected stored procedure returns no columns" hatası alabilirsiniz. Bunu çözmek için Table variables kullanabilirsiniz.



Örnek

-- tablevariable declare edilir ve içinde dönecek kolonlar tipleri ile belirtilir.

Declare @MyTableVar table

(Hab int,

Ord int,

TiBas nvarchar(max)

)



-- table variable ilgili sp sonucu atanır

Insert @MyTableVar Exec Cms_Anasayfa_SelectedNews_Select



-- atanan değer çağırılır.

Select * from @MyTableVar

Table variables

Table Variables
objects
objects
Table variables are objects similar to temporary tables and were introduced in SQL Server 2000. A table variable is declared using the table data type. A statement declaring a table variable initializes the variable as an empty table with a specified structure. As a table definition, such a statement includes definitions of columns with their data type, size, precision, and optional constraints (primary key, identity, unique, and check constraints). All elements have to be defined during the declaration. It is not possible to alter or add them later.

The following batch declares a table variable, inserts rows, and returns them to the user:


Declare @MyTableVar table
(Id int primary key,
Lookup varchar(15))

Insert @MyTableVar values (1, '1Q2000')
Insert @MyTableVar values (2, '2Q2000')
Insert @MyTableVar values (3, '3Q2000')

Select * from @MyTableVar
Go
Read more at searchsqlserver.techtarget.com
 

Yorumlar

Bu blogdaki popüler yayınlar

22.06.2020 - 26.06.2020 arası işler

Asp.net RestSharp ile data post etmek

List Box Item içindeki elemanları aşağı veya yukarı taşımak