Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problem with function

Author  Topic 

thiyait
Yak Posting Veteran

70 Posts

Posted - 2004-10-08 : 14:57:45


My need of call is getting the query like this

i needed the query like this so i call the another function to retrive data
Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in ('8','9','10' )

Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in dbo.GetuserTempid(@PortalId,@userid,@tabid)........this is calling fucntion


My coding follows:

First Function 1:
CREATE FUNCTION dbo.getfinalresult (@portalid as int ,@userid as int ,@tabid as int)
RETURNS nvarchar(100) AS
BEGIN
declare @tempauth nvarchar(50)
declare @id as int
declare @userIds varchar(100)
Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in dbo.GetuserTempid(@PortalId,@userid,@tabid)
Select @tempauth= '('+@userIds+')'
return @tempauth
END



second function 2:

CREATE function GetuserTempid(@PortalId int,@userid int,@tabid int )
returns nvarchar(50) as
begin
declare @tempuserid as nvarchar(100)
set @Tempuserid =( SELECT '(''' + REPLACE(LEFT(LTRIM(RTRIM(authorizedroles)), LEN(LTRIM(RTRIM(authorizedroles)))-1), ';', ''',''') + ''')' FROM tabs WHERE tabid = @tabid)
return @tempuserid /*Tabs table return the query like this :('4','5','5')
end

Note:

Table tabs contain:

select authorizedroles from tabs WHERE tabid = @tabid

result:
authorizedroles
8
9
10

but i needed format is ('8','9','10')
Function two return the above specified format

Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in dbo.GetuserTempid(@PortalId,@userid,@tabid)/* show the syntax error*/


Guys any body help me.......

thiyait
Yak Posting Veteran

70 Posts

Posted - 2004-10-08 : 15:32:17
quote:
Originally posted by thiyait



My need of call is getting the query like this

i needed the query like this so i call the another function to retrive data
Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in ('8','9','10' )

Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in dbo.GetuserTempid(@PortalId,@userid,@tabid)........this is calling fucntion


My coding follows:

First Function 1:
CREATE FUNCTION dbo.getfinalresult (@portalid as int ,@userid as int ,@tabid as int)
RETURNS nvarchar(100) AS
BEGIN
declare @tempauth nvarchar(50)
declare @id as int
declare @userIds varchar(100)
Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in dbo.GetuserTempid(@PortalId,@userid,@tabid)
Select @tempauth= '('+@userIds+')'
return @tempauth
END



second function 2:

CREATE function GetuserTempid(@PortalId int,@userid int,@tabid int )
returns nvarchar(50) as
begin
declare @tempuserid as nvarchar(100)
set @Tempuserid =( SELECT '(''' + REPLACE(LEFT(LTRIM(RTRIM(authorizedroles)), LEN(LTRIM(RTRIM(authorizedroles)))-1), ';', ''',''') + ''')' FROM tabs WHERE tabid = @tabid)
return @tempuserid /*Tabs table return the query like this :('4','5','5')
end

Note:

Table tabs contain:

select authorizedroles from tabs WHERE tabid = @tabid

result:
authorizedroles
8
9
10

but i needed format is ('8','9','10')
Function two return the above specified format

Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in dbo.GetuserTempid(@PortalId,@userid,@tabid)/* show the syntax error*/


Guys any body help me.......


Dont confuse with huge written


This is my need query:............
Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in ('8','9','10' )

Select @userIds = isnull(@userIds+',''','''') + convert(varchar,userId) + '''' from userroles where roleid in dbo.GetuserTempid(@PortalId,@userid,@tabid)?/*.. getusertempid reurn the result......Sql show the error .........


help meeeeeeeeeeeeeeee...........
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-10-08 : 15:48:45
What does huge written even mean?

Anyway, go to the front page of SQLTeam.com. Type in csv in the article search. You'll find your solution in an article here.

Tara
Go to Top of Page
   

- Advertisement -