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.
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? Thxuse bungi;goCREATE FUNCTION dbo.checkPermissions(@ItemPermissionsList varchar(8000),@UserPermissionsList varchar(8000)) RETURNS bitAS 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 @ReturnENDgoGRANT EXECUTE ON [dbo].[checkPermissions] TO [sqlaccount]GRANT EXECUTE ON [dbo].[checkPermissions] TO [bungidbname]goCREATE 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 ENDgoGRANT EXECUTE ON [dbo].[checkPermissions] TO [sqlaccount]GRANT EXECUTE ON [dbo].[checkPermissions] TO [bungidbname]go |
|
|
|
|
|
|