如何使用缩放器函数的返回值创建列 [英] How to create column using scaler function return value

查看:66
本文介绍了如何使用缩放器函数的返回值创建列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我多次调用定标器函数时,它会将值返回到不同的行中,我想将其查看到不同的列中,请告诉我它的语法
就像我应该在多个函数中使用哪个运算符一样

when i call scaller function more than one time it return the value into different rows i want to view it into different column please tell me the syntex for it
like which operator should i use among more than one select of function like

SLECT [PunjabItLabs].[dbo].[CompalintsStatusBySI] (
   'Inbox',0) as closed
     select [PunjabItLabs].[dbo].[CompalintsStatusBySI] (
   'Inbox',1) verified


我想查看已关闭并验证为不同的列

感谢


i want to see closed and verifies into different column

thanks

推荐答案

伊拉姆,

您可以像这样在单个SELECT语句中两次调用该函数...


Hi Iram,

You can call the function twice in a single SELECT statement like this...


SELECT [PunjabItLabs].[dbo].[CompalintsStatusBySI] (''Inbox'',0) as closed
,[PunjabItLabs].[dbo].[CompalintsStatusBySI] (''Inbox'',1) verified



将它们放在具有不同列的单行中的第二种方法.如果可以将[PunjabItLabs].[dbo].[CompalintsStatusBySI]转换为表值函数,则将其转换为第二个参数.在函数主体中声明两个变量,以保存已关闭和已验证的标量值.将它们分配给您现有的已关闭且已验证的查询标量结果,然后使用这两个变量将close(0)和verify(1)的标量结果都插入到临时表中,然后将其返回.这是示例代码..



The second way to get them in single row with different columns. If it is possible to convert [PunjabItLabs].[dbo].[CompalintsStatusBySI] into table valued function,then convert it,remove the second parameter. Declare two variable in the function body to hold the closed and Verified scalar values. Assign them with your existing closed and verified query scalar results and insert the both closed(0) and verified(1) scalar result into the temp table using the both the variables and return it. Here is the sample code..

 ALTER FUNCTION [PunjabItLabs].[dbo].[CompalintsStatusBySI]
 (@Type VARCHAR(20))
 RETURNS @result TABLE(Closed INT,Verified INT)
 AS
 BEGIN
  DECLARE @Closed INT = 0
  DECLARE @Verified INT = 0

 SELECT @Closed = --Your Query to get the closed scalar
 SELECT @Verified = --Your Query to get the Verified scalar

 INSERT INTO @result VALUES(@Closed,@Verified)

 RETURN
 END

-- After this call this function in select query

SELECT * FROM [PunjabItLabs].[dbo].[CompalintsStatusBySI]('Inbox')



选择适合您需求的选项之一.



Choose one of the options which suits your requirement.


这篇关于如何使用缩放器函数的返回值创建列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆