In saclar- Valued function multiple column name data display data in single cell, using scalar-valued function.
Create registration table
- CREATE TABLE [dbo].[Registration]
- (
- [RId] [bigint] IDENTITY(1001,1) NOT NULL,
- [Name] [varchar](100) NULL,[DOB] [datetime] NULL,
- [RegDate] [datetime] NULL,
- [Address] [varchar](200) NULL,
- [State] [varchar](100) NULL,
- [District] [varchar](100) NULL,
- [Email] [varchar](100) NULL,
- [MobileNo] [varchar](100) NOT NULL,
- [PostId] [varchar](100) NULL,
- [SponserRID] [bigint] NULL,
- [SponserPost] [varchar](50) NULL,
- [LoginId] [varchar](50) NULL,
- [Password] [varchar](50) NULL,
- )
Create scalar-valued function
- CREATE FUNCTION [dbo].[fn_NameMobile]
- (@id varchar(100))
- RETURNS VARCHAR(100)
- AS
- begin
-
- RETURN
- (
- select Name +' '+'['+cast(mobileno AS VARCHAR)+']' +' '+'['+cast(loginid AS VARCHAR)+']' as Name from Registration WHERE RId = @id
- )
-
- END
-
- GO
Query and output
select Name,mobileno,loginid from registration where RId='1024'
select dbo.fn_NameMobile(1024) as Name_MobileNo_LoginID