How many ways to create table-valued functions?



How many ways to create table-valued functions?..

Answer / Saurabh Gautam

There are two primary ways to create table-valued functions in MS SQL Server: Inline Table-Valued Functions (ITVF) and Multi-Statement Table-Valued Functions (MSTVF).n
1. Inline Table-Valued Function:n```sql
CREATE FUNCTION itvf_function()
RETURNS TABLE
AS
RETURN ( SELECT column1, column2, ... FROM table );
```
Replace `column1`, `column2`, and so on with the appropriate columns from your table.n
2. Multi-Statement Table-Valued Function:nFirst create a temporary table to store the results:n```sql
CREATE FUNCTION mstvf_function()
RETURNS TABLE
AS
BEGIN
CREATE TABLE #tempTable ( column1 data_type, column2 data_type, ... );
INSERT INTO #tempTable ( column1, column2, ... ) SELECT column1, column2, ... FROM table;
RETURN #tempTable;
END;
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

what are constraints? : Sql server database administration

1 Answers  


‘Order by’ is not allowed in a view how can you sort information from a view?

1 Answers  


What are orphan records?

1 Answers  


what is replication? where do u use Go Keyword?

1 Answers   Satyam,


What is the use of stored procedure?

1 Answers  


is there a column to which a default can't be bound? : Sql server database administration

1 Answers  


1. Tell me your daily activities 2. If sql server installation fails at time installation what will do 3. Where does the sql server installation log details are stored 4. After the installation what will you do for memory configuration 5. What is the difference between SQL max maximum memory and AWE memory 6. How will you configure AWE memory 7. How will setup an email alert for the backup job 8. After the SQL installation what are the jobs will you configure 9. What does –g mean in the sql startup parameter 10. What is the difference between Bulked log and Full recovery model 11. What is the difference between mirroring and log shipping 12. What are the steps to be followed before in-place up gradation 13. After installing the patch the sql server does not start and application team tells to rollback the changes .In this scenario what will you do

1 Answers   CSC, IBM,


Can you please differentiate between a primary key and a unique key?

1 Answers  


Differentiate between sql temp table vs table variable?

1 Answers  


What is sql injection and why is it a problem? : sql server security

1 Answers  


Is it true, that there is no difference between a rule and a check constraint?

1 Answers  


What is DAC? what is the use of it?

1 Answers   Wipro,


Categories