Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

DECLARE a variable inside function in SQL Server?

Asked by Anne Bell Apr 16, 2021 165 views 1 answer
Share

About this question

In my stored procedure, I have table variable with a lot of columns. Because I want to simplify the stored procedure I thought i could declare table variable in function like CREATE FUNCTION [dbo].[ufn_DeclareMaterialTableVariable] ( ) RETURNS @returntable TABLE ( [Id] [int] NULL, [Number] [int] NOT NULL, [Name] [nvarchar](255) NULL, ... dozens of columns ) AS BEGIN RETURN END but i realized i don't know, how to use it. My idea was something like select * into @table from [dbo].[ufn_DeclareMaterialTableVariable] but this is not gonna work, unless i use temporary table. The second idea is to declare table with custom data type. declare @table TABLE as CustomTableType but this is also not working. Any idea ?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.