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
 SQL Server Administration (2000)
 trying to run a dos batch script

Author  Topic 

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-02-05 : 10:08:20
Hi,

basically whenever i create a new db i need to create several UDFs as well. I'd like to write a dos bacth script to do this. Basically I have the followjng sql scrip that I want to run. (I have just included 2 UDFs in it for now)

I understand I need to use OSQL? Also is there a way to pass in the database name to this script (use bungi). Ideally i'd like a way to make this an executable bacth job and pass in variables.... Does anyone have any experience in this? Thx

use bungi;
go

CREATE FUNCTION dbo.checkPermissions(@ItemPermissionsList varchar(8000),@UserPermissionsList varchar(8000))
RETURNS bit
AS
BEGIN
declare @Return bit
declare @Value varchar(8000)
set @Return = 1
set @ItemPermissionsList = @ItemPermissionsList + ','
While (Charindex(',',@ItemPermissionsList)>0)
Begin
Set @Value = ltrim(rtrim(Substring(@ItemPermissionsList,0,Charindex(',',@ItemPermissionsList))))

if (@Value!=null AND @Value!='')
begin
set @return = case WHEN Charindex(@Value,@UserPermissionsList) > 0 THEN @return ELSE 0 END
END

Set @ItemPermissionsList = Substring(@ItemPermissionsList,Charindex(',',@ItemPermissionsList)+1,len(@ItemPermissionsList))
End

Return @Return
END
go
GRANT EXECUTE ON [dbo].[checkPermissions] TO [sqlaccount]
GRANT EXECUTE ON [dbo].[checkPermissions] TO [bungidbname]
go


CREATE FUNCTION dbo.concatSubscriberGroups(@id int)
RETURNS NVARCHAR(4000) AS
BEGIN
DECLARE @Output VARCHAR(4000)
SELECT @Output = COALESCE(@Output+'',',') + CONVERT(varchar(20), group_id) + ','
FROM group_subscrb_XREF group_subscrb_XREF
WHERE group_subscrb_XREF.subscriber_id = @id
ORDER BY group_subscrb_XREF.group_id asc
RETURN @Output
END
go

GRANT EXECUTE ON [dbo].[checkPermissions] TO [sqlaccount]
GRANT EXECUTE ON [dbo].[checkPermissions] TO [bungidbname]
go
   

- Advertisement -