I created that SP to populate ComboBox. Just show how to concatenate columns in SELECT statement under IF statement for SP parameter? Why in my code in SELECT concatenation not works
you cannot do this @SelectString = Last_Name+', '+First_Name EmployeeName
give an alias to the concatenation while also assigning it to a variable. it is one or the other
create table #Employees(First_Name varchar(50), Last_Name varchar(50))
insert into #Employees
select 'eu', 'gz' union
select 'harish', 'gg1' union
select 'yosias', 'z'
go
create proc getemployees_sp
(@SelectText int)
as
begin
Declare @SelectString as varchar(100)
If @SelectText = 0
select 'Select'
Else
SELECT Last_Name +', '+ First_Name as EmployeeName
FROM #Employees
end
go
exec getemployees_sp 3
go
drop table #Employees
drop table #Employees
go
create table #Employees(First_Name varchar(50), Last_Name varchar(50))
insert into #Employees
select 'eu', 'gz' union
select 'harish', 'gg1' union
select 'yosias', 'z'
go
select * from #Employees
go
stored proc
CREATE PROCEDURE Getemployees_sp (@getresults INT)
AS
SET nocount ON;
DECLARE @t TABLE
(
first_name_last_name VARCHAR(50)
)
IF @getresults = 0
INSERT @t
SELECT 'SELECT'
ELSE
INSERT @t
SELECT last_name + ', ' + first_name
FROM #employees
SELECT *
FROM @t
go