How To Grant Rights For The Anonymous IIS Web User IUSR_.. To Execute Scalar Function In Assembly

Jul 26, 2006

Dear all,

Basically I want to set chain up the rights so that the anonymous web user IUSR_ .. can execute the new .NET subs, functions etc in the assembly, just as the anonymous web user can execute Stored Procedures when granted. In this way, it should be possible to call the .NET assembly just as classic stored procedures from ASP/ASP.NET.

I have written a .NET function which I can successfully execute if I log on to the database as an administrator by sending this T-SQL query; it returns the result of a given string:

select dbo.CLRHTMLString('abc')

The scenario is now to try to grant access to this assembly for a different role (webuser), which the classic IUSR_MYSERVERNAME is a login of, so that I can call the .NET Assembly when I am authenticated as the anonymous web user (e.g. via ASP, etc.).

To test access, I created a login (webusertest) for a user (webusertest) in the same role (webuser) on the database. But when I use this login, which supposedly has the same rights as the IUSR_, execution right is denied:

EXECUTE permission denied on object 'CLRHTMLString', database 'adt_db', schema 'dbo'.

Note: The 'webuser' database role has Execute permission on the Assembly.

I have also tested this from my actual web page, with the following results:
(1) IUSR_MYSERVER member of db_owner role: Web page has right to call assembly.
(2) IUSR_MYSERVER not member of db_owner role: Web page does not have right to call assembly.

Further test results:
(3) Function can be called when making the user "webusertest" member of the "db_owner" role, which is too much rights to grant for the anonymous web user.

(4) When adding the user 'webusertest' to get 'Execute' permissions on the assembly, it does not get added. After clicking OK, there is no warning message, but when opening the Assembly Properties -> Permission dialog box the same time, the 'webusertest' user does not appear in the list.

Thankful for any advice on this matter.

View 4 Replies


ADVERTISEMENT

SQL Security :: How To Grant User Rights To Edit Job Description

Aug 27, 2015

What's best practice (security wise) in granting a user access right to edit say the description of a job.

View 2 Replies View Related

How Can I Execute Stored Procedures With Correct User Rights?

Sep 3, 2007

Hi,

I have a problem with sp execution.:







objects of [dbo]

Tables of [nuran]

Grants of [nuran]


[dbo].tabloA

[nuran].tmptabloA

Select,insert, update on [dbo].tabloA


[dbo].tmptabloA



Deny for [dbo].tmptabloA


[dbo].sp_yordam



Grant for executing [dbo].sp_yordam









(1)
create PROCEDURE [dbo].[SP_yordam]
AS
BEGIN

BEGIN TRANSACTION @Tran1
€¦€¦€¦€¦€¦. €¦€¦€¦€¦€¦€¦ €¦€¦€¦€¦.

INSERT INTO [tabloA]
(, ,)
SELECT ,,
FROM [tmptabloA] WHERE ......

€¦€¦€¦ €¦€¦€¦ €¦€¦€¦.

DELETE FROM [tmptabloA]

COMMIT TRANSACTION @Tran1


When user [nuran] execute the procedure sp_yordam by a VB program, the procedure use [dbo].tmptabloA not [nuran].[tmptaboA]. If there are data in the [dbo].tmptabloA, the procedure insert data to [dbo].tabloA from [dbo].tmptabloA. But when I checked user name in the procedure during execution, the user was [nuran].

If I write the procedure like that:

(2)
create PROCEDURE [dbo].[SP_tmpSil]
AS

declare @tablo1 as varchar(50),
DECLARE @sil as nvarchar(max)
select @tablo1='[tmptabloA]'

SELECT @sil = ' DELETE FROM ' + @tablo1 + ';'
EXEC (@sil)

END

And it executed by user [nuran],then it used the correct table [nuran].tmptabloA

Is there any way to use user€™s table in an stored procedure without using the user name :
(3)
create PROCEDURE [dbo].[SP_yordam]
AS
BEGIN

BEGIN TRANSACTION @Tran1
€¦€¦€¦€¦€¦. €¦€¦€¦€¦€¦€¦ €¦€¦€¦€¦.

INSERT INTO [tabloA]
(, ,)
SELECT ,,
FROM [nuran].[tmptabloA] WHERE ......

€¦€¦€¦ €¦€¦€¦ €¦€¦€¦.

DELETE FROM [nuran].[tmptabloA]

COMMIT TRANSACTION @Tran1


I don't want to use (2) and (3) code methods, I prefer to use (1) script. Is there any compilation method, or any aditional way for using script (1) with correct user rights?

Thanks a lot

Nuran

View 4 Replies View Related

Minimum Set Of Permissions And User Rights To Execute A Report Definition

Jan 28, 2008

To use Reporting Services as a rendering engine I want to configure a local user on the server that has only the minimum set of permissions and user rights. The server is W2K3 SP2 and SQL 9.0.3200.

In particular, this local user has been removed from the local "Users" group and so is the "Authenticated Users" built-in group. In Reporting Services, it is mapped to a role that only has the "Execute Report Definitions" task permission.

Then, following the details in http://support.microsoft.com/kb/812614/ (Default permissions and user rights for IIS 6.0) I added all file security and local user rights required for "Users" and also granted and propagated "Read&Execute" on the "Reporting Services" folder and verified this using "Effective Permissions" on the ReportService2005.asmx file.

However, I still get 401 Unauthorized, also after a complete restart of all related machines and services.

Once I add the user or "Authenticated Users" back to "Users" everything works fine.

What permissions might I be missing? Where could I find those permission requirements documented?

I tried analyzing the 401 using auditing file and object access security but to no avail. There are no Failure audit entries in the Security log.


How can I investigate the minimum permission set?

What is the risk of leaving the user in the "Users" local group?


Any help appreciated.

View 1 Replies View Related

IUSR_ To Run Function, Drop Table..

Jul 15, 2007

Helo all,
i dont know if that is the right way, but i was wanted to make kind of sql profiler on a webpage :) and cool features would be to usa ajax to fire it async in some time secvence.. ok, ok, here goes my code and expla... i have sql2005 (express edition,, cose i think its so cool and for a lot of projects can be used for), attached startup procedure, whit> sp_procoption 'kreni_instanco_moja', startup, true, and kreni_insta... is like:
----------------set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[kreni_instanco_moja]ASBEGINexec kp.dbo.start_traceEND----------------
ok and my start_trace is:
----------------ALTER PROCEDURE [dbo].[start_trace]ASBEGINDECLARE @traceidnum INT,@on BIT,@file_path NVARCHAR(50),@maxsize bigint;SET @on = 1;SET @maxsize =5;SET @file_path = 'O:BU_DATABASE' + convert(varchar,getdate(), 102);EXEC sp_trace_create @traceid = @traceidnum OUTPUT, @options = 2, @tracefile = @file_path, @maxfilesize = @maxsize, @stoptime=null, @filecount =0;EXEC sp_trace_setevent 2, 12, 1, @on -- ili 12 ili 13EXEC sp_trace_setstatus 2, 1 -- 1 = START, 0 = STOPEND----------------
actual code that brings table and shows sql executed is:
----------------use kpdrop table traceselect textdata into trace fromfn_trace_gettable(N'O:BU_DATABASE' + convert(varchar,getdate(), 102) + '.trc',1)select textdata from tracego----------------
and it works fine,, but when its fired from my local admin connection, and try that whit IUSR*???? not going... ok, i think that IUSR have to have privilage to open that O:BU_DATABASE ... file, and to have priv to drop tabel and to fire that function..fn_trace_get ... ?? so, that is where i got stuck up... any help would be veryyyy apreciated... hey, we can put some kind of project if anybody is interested! :) to have admin page and to monitor sql code that is executed,,, and remotely
if i was not clear in some explaining, you can ask me and ill try better
thenx, kpendic

View 2 Replies View Related

Grant Execute On Sproc Doesn't Grant Privilege To Update?

Oct 31, 2014

I am writing a stored procedure which updates a table, but when I run the stored procedure using a login that I have granted execute privileges on, then I get a message that I cannot run an update on the table. This would happen in dynamic sql... while my SQL has parameter references, I don't think it is considered dynamic SQL?

sproc:
CREATE PROCEDURE [schemaname].[SetUserCulture]
@UserID int
, @Culture nvarchar(10)
AS
UPDATE dbo.SecUser
SET Culture = @Culture
WHERE UserID = @UserID

execute SQL:
EXEC schemaname.SetUserCulture @UserID = 9, @Culture = N'x'

error:
The UPDATE permission was denied on the object 'SecUser', database 'DatabaseName', schema 'schemaname'.

View 8 Replies View Related

Grant Rights To Public

Apr 26, 2001

Can I grant rights to "public" role ( customize it). Our app uses it.

thanks,

View 1 Replies View Related

Grant All Rights On All Db Objects

Sep 13, 2000

Is there a command that will grant all rights select, delete, update, execute
on all objects in a database to a user? But not be DBO

View 2 Replies View Related

NEED HELP For GRANT Rights To Views?

Sep 13, 2006

I want to grant rights (delete, select...) to all my views.

the statement is eg.: grant delete on view1 to public

I have more than 2000 views. Therefore I do not want to use the statement 2000 times. Is there a possibility to grant rights to all or a part of my views with one statement.

thanks for help



Elmar

View 8 Replies View Related

.NET Framework :: Grant DnsPermission To Assembly?

May 3, 2015

Ported RabbitMQ over to .NET 3.51 over without the SYstem.ServiceModel dependencies.My SQL CLR Proc invokes rabbit to publish a message but then gets a DNS error because of limited permissions:

RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.Security.SecurityException: Request for the permission of type 'System.Net.DnsPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.

[Code] .....

What's strange is that I added the RabbitMQ assembly with the unsafe option so it seems like this should just work with no CAS headaches:

CREATE ASSEMBLY [RabbitMQ.Client]
Β  Β  Β  Β  Β  Β FROM 'c:SqlClrRabbitMQ.Client.dll' WITH PERMISSION_SET = UNSAFE
GO

How do I get by the DNSPermission check in SQL CLR?

View 4 Replies View Related

Reporting Services Migration - Create Grant Rights Script: Failed

Dec 14, 2007

Hi,

We moved a development reporting services database to a new server last night and followed the MS 'Moving a Report Server Database to another computer' directions. We used the Reporting Services Config tool to make the changes, remoted into the 2003 windows server - which is running sql Enterprise reporting and connecting to a 2005 Enterprise cluster.

We had two small problems - although everything seems to be working fine. The First try seemed to be unsuccessful because we did have the service started after applying the database connection changes. The directions don't mention starting the service before you hit apply. The second time we got an error that said "Create Grant Rights Script - The Task Failed". We entered a sql login that was a sysAdmin during the setup.

The exception details started off with:
System.UnauthorizedAccessException: Access is denied

If the rest of this error is needed I can type it out...I was sent a screen shot of it!
Thanks for any help - we are moving production soon and I'd like to understand what went wrong.
Thanks
Sam

View 3 Replies View Related

Using User Defined Function In Execute SQL Task Within Foreach Loop

Jul 19, 2007

hi



I am trying to execute a UDF in an Execute SQL Task within a Foreach loop.

I have an Execute SQL task to get the dataset (Firstname, Lastname, CompanyID) which is going into a full result set called @PendingPar. The Foreach Loop is set to a Foreach ADO Enumerator against @PendingPar and I have created 3 variables at the Foreach Loop scope level called @Firstname (String), @Lastname (String) and @CompanyID (Int32). These are mapped in the Foreach Loop as index 0,1 and 2.



Within the Foreach Loop I have an Execute SQL Task with the sql command



select dbo.udf_GetParTitle (?,?,?)



In the parameter mapping I have Variable Name = User::Firstname Direction = Input Data Type = VARCHAR and Parameter Name = 0, User::Lastname, Input, VARCHAR, 1 and User::CompanyID, Input, VARCHAR,2



Finally the UDF returns a @NewPar value so i have the result set in the execute sql task to Single Row which goes into variable @NewPar. This @newPar will be used later but I cannot get the first bit to work yet.



the error message i get back is



Error: 0xC002F210 at Execute SQL Task 1, Execute SQL Task: Executing the query "select dbo.udf_GetParTitle (?,?,?)

" failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Task failed: Execute SQL Task 1



the initial execute sql task where the dataset is selected works fine but it is within the foreach loop that it fails.



any help gratefully recieved



View 6 Replies View Related

Execute Scalar ?

Sep 20, 2007

I'm trying to do something like the code below, but it's saying "specified cast is not valid"
If i change the value returned to an "int", it works fine. My issue is, i'd like to get the value returned with more accuracy than an int as there will be 2 decimal places.protected float getProjectHours(string project)
{string selectCmd = "SELECT SUM(hours) FROM tasks WHERE project=@project";
string strConnection = ConfigurationManager.ConnectionStrings["TimeAccountingConnectionString"].ConnectionString;SqlConnection myConnection = new SqlConnection(strConnection);
SqlCommand myCommand = new SqlCommand(selectCmd, myConnection);myCommand.Parameters.Add(new SqlParameter("@project", SqlDbType.VarChar));myCommand.Parameters["@project"].Value = project;
myConnection.Open();float total = (float)myCommand.ExecuteScalar();
myConnection.Close();
return total;
}

View 6 Replies View Related

Execute Scalar Question

Sep 20, 2006

Im using the following code in my application. Is it redundent to add the "Top 1" to the select or does it help performance? Thanks string strSQL = "SELECT TOP 1 c.CusId " +
"FROM COCUS c " +
"LEFT JOIN CONOTITM n ON c.NotId = n.NotId " +
"WHERE c.CusId NOT IN(SELECT CusId FROM RDK_PROSPECT_LOCK WHERE EmpId <> '" + USER.ID() + "') " +
"ORDER BY n.DateUpdate, c.DateUpdate ASC";


string strCusID = RDK.DATA.ReturnScalar(strSQL);  

View 2 Replies View Related

Problem With Execute.scalar()

Oct 13, 2007

 Hello, I've got the following code: Dim Selected1 Dim cnn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString1").ToString()) Dim SqlCommand As New Data.SqlClient.SqlCommand("SELECT [OKTipp1] FROM [ErsteSchritte] WHERE (User.Name = @UserName)", cnn) SqlCommand.Parameters.Add("@UserName", Data.SqlDbType.VarChar, 30) SqlCommand.Parameters("@UserName").Value = User.Identity.Name cnn.Open() Selected1 = SqlCommand.ExecuteScalar() cnn.Close() MsgBox(Selected1)Unfortunatly, I am given an error message. What did I do wrong?Thanks for any suggestionsRegards 

View 7 Replies View Related

SQL 2012 :: How To Grant A New User Same Direct Privilege To Tables As Existing User

Feb 18, 2014

I am relatively new to sql developer. There is a new user that just joined our organization. I am trying to grant him the same direct grants privilege to the tables that an existing user has. The existing user has a ton of direct table access privileges and it will take days if I had to do each grant one by one like: grant select,insert,delete,update on 'table name' to 'user id'. Is there a way of copying or inserting an existing user's privilege and granting it to a new user.

View 2 Replies View Related

Error With NULL Using EXECUTE SCALAR

Dec 11, 2007

I keep getting an error message when I try to place the result of an execute scalar command into a text box.  The msg is:"conversion from 'DBNull' to type 'String' is not valid"
The code I am using is:
 
Dim con as OLEDBConnection
con =NewOleDB connection("Provider = MIcrosoft.JetOLEDB.4.0, Data Source = "c:caps.mdb")
Dim cmd As OLEDBCommand
cmd= NewOLEDBCommand("Select Product from [Inventory Table] Where [Customer ID] = " & grid View1.SelectdValue
texBox1.Text = cmd.ExecuteScalar
 
The code works fine as long as there is a value for the Product.  However if the value in the database is NULL I get an error message: :"conversion from 'DBNull' to type 'String' is not valid". How do I wok around this?
Chas28
 

View 4 Replies View Related

GRANT EXECUTE ON [GRANT EXECUTE]

May 6, 2008

Hi,

I want one of my database users to be able to grant execute to procedures, but I don't want the user to have sys admin rights.

Is this possible. Kind of a statement like the following:

GRANT EXECUTE ON [GRANT EXECUTE] TO myuser

Thanks in advance

View 9 Replies View Related

UD Scalar Function

Mar 5, 2008

I want to add four fields of a table and place the toatal in a new field.Also I wanna have the average of the fields.

For e.g
I have created a marksheet having four subjects.Now I wanna add the subjects and find the average of the subjects and place them in two different fields in the same table along with the respective names in the table.Pls help.

Thanks in advance.

View 8 Replies View Related

&#34;Execute Any Procedure&#34; Grant?

Feb 9, 2001

I am trying to set up a security system for my senior developers where they automatically can execute any procedure. It is in the System Administrator server role. Is there any way I can grant this role to their database role withour giving them complete System Adminstrator rights?

View 3 Replies View Related

How To Grant Execute On Xp_cmdshell??

Apr 2, 2002

Can anyone help me please.
Healp please.
Does anybody know how to make xp cmdshell runnable for users other than Admin. It should be possible to grant execute to others, but i can't figure out how.

This is what i found:

Be aware that when you grant execute permission for xp_cmdshell to users, the users will be able to execute any operating-system command at the Windows NT command shell that the account running SQL Server (typically local system) has privilege to execute.

To restrict xp_cmdshell access to users who have administrator permission on the Windows NT-based computer where SQL Server is running, use SQL Setup or SQL Enterprise Manager to set the server options, selecting the "xp_cmdshell - Impersonates Client" option. With this option selected, only users who have connected to SQL Server via a trusted connection and are members of the local Administrators group on that computer are allowed to use xp_cmdshell. The commands run by xp_cmdshell continue to execute in the server's security context.

View 1 Replies View Related

Xp_cmdshell Execute Rights (2005)

Sep 11, 2006

I was trying to grant access for an application user for executing xp_cmdshell, but I got some error message saying that either doesn't the user exist, or I don't have the permissions to grant this. Does the user need to be a user in Master ? Or, don't I when logged in as "sa" have the sufficient permissions to grant execute on a SP in master?

I solved it by checking "Control server" under "Properties" > "Securables"
for the login, but I don't actually want this login to have full control.

(And yes, I've read that allowing xp_cmdshell usage isn't recommended at all.)

View 3 Replies View Related

T-SQL (SS2K8) :: UDF Scalar Value Function

Jun 24, 2015

I build a UDF scalar function like this:

CREATE FUNCTION VerificaAcessoPerfil
(
@codigo INT
)
RETURNS INT

[Code] ....

Curiously when i call my function the same one return always the same value, ex:

Select VerificaAcessoPerfil(2)

the return value is : 698 ??

but if i run the Select statment like this:

SELECT DISTINCT codigo,
(case codigo WHEN 1 THEN 695
WHEN 11 THEN 697 WHEN 2 THEN 211
WHEN 10 THEN 698 WHEN 13 THEN 696
WHEN 4 THEN 1 END)[codigo]
FROM pf (NOLOCK) INNER JOIN pfu (NOLOCK) ON pfu.pfstamp=pf.pfstamp
WHERE codigo IN (1,11,2,10,13,4)
ORDER BY 1 ASC

The value are:

1695
2211
41
10698
11697
13696

View 9 Replies View Related

Scalar Function Columns

Jul 20, 2005

Is it ill-advised to have columns whose values pull from scalar functionsusing other fields in the record as parameters? For example, if I havecreate table a(iID int primary key)create table b(iID int ,iDetail int,CONSTRAINT PK PRIMARY KEY(iID,iDetail),CONSTRAINT FK FOREIGN KEY (iID) REFERENCES a(iID))Let's say in table b I put price information for each detail and in table aI'd like to put a column that sums these prices for the children of eachrecord. Should I make a computed column that references a function usingiID as a parameter? Or would it be better to create a view for this kind ofpurpose?Regards,Tyler

View 4 Replies View Related

Grant Create - And Execute - Procedures

May 6, 2008

I am creating a login with a user in one database. The id has to
create procedures in the dbo schema, execute them, and grant execute on them to other users.
BOL says to
GRANT ALTER ON SCHEMA::DBO TO username ;
GRANT CREATE PROCEDURE TO username ;
I did that. User can now create procedures, but cannot execute what he creates. And cannot grant execute on the sp to anybody.

I don't want to give this id a lot of priviledges.

View 16 Replies View Related

Grant Execute Permission In 2000

Dec 11, 2006

does anyone know how to do this, its :

GRANT EXECUTE ...

for 2005 but for 2000?

View 6 Replies View Related

How Do I Grant Execute/edit For A DTS Package?

Mar 3, 2008

Hi, I have created a DTS Package in SQL Server 2000, is there any way that a different user can edit and execute that DTS WITHOUT having server roles?


Thanks

View 6 Replies View Related

Script To Grant Execute For Sprocs

Aug 7, 2007

Hello.

I'm using what looks to be a popular script to grant execute privileges to stored procedures, and it works great as long as the user account that you want to grant to is not a domain account.
For example, I need to grant execute to myDomaindbUsers, but get a syntax error when the script tries to execute this statement:


SET @SQL = 'GRANT EXECUTE ON [' + @Owner

+ '].[' + @StoredProcedure

+ '] TO myDomaindbUsers'


Incorrect syntax near ''.




The script works fine if a non-concatenated user account is given.
We use Active Directory to manage our access, thus the domaingroup.
Has anyone found a way around this?
Thanks in advance.

Tess


Here's the entire script for anyone who's interested:




USE whateverDatabase

GO

DECLARE @SQL nvarchar(4000),

@Owner sysname,

@StoredProcedure sysname,

@RETURN int

-- Cursor of all the stored procedures in the current database

DECLARE cursStoredProcedures CURSOR FAST_FORWARD

FOR

SELECT USER_NAME(uid) Owner, [name] StoredProcedure

FROM sysobjects

WHERE xtype = 'P'

AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(USER_NAME(uid)) + '.' + QUOTENAME(name)), 'IsMSShipped') = 0

AND name LIKE 'p%'

OPEN cursStoredProcedures

-- "Prime the pump" and get the first row

FETCH NEXT FROM cursStoredProcedures

INTO @Owner, @StoredProcedure

-- Set the return code to 0

SET @RETURN = 0

-- Encapsulate the permissions assignment within a transaction

BEGIN TRAN

-- Cycle through the rows of the cursor

-- And grant permissions

WHILE ((@@FETCH_STATUS = 0) AND (@RETURN = 0))

BEGIN

-- Create the SQL Statement. Since we€™re giving

-- access to all stored procedures, we have to

-- use a two-part naming convention to get the owner.

SET @SQL = 'GRANT EXECUTE ON [' + @Owner

+ '].[' + @StoredProcedure

+ '] TO myDomaindbUsers'

-- Execute the SQL statement

EXEC @RETURN = sp_executesql @SQL

-- Get the next row

FETCH NEXT FROM cursStoredProcedures

INTO @Owner, @StoredProcedure

END

-- Clean-up after the cursor

CLOSE cursStoredProcedures

DEALLOCATE cursStoredProcedures

-- Check to see if the WHILE loop exited with an error.

IF (@RETURN = 0)

BEGIN

-- Exited fine, commit the permissions

COMMIT TRAN

END

ELSE

BEGIN

-- Exited with an error, rollback any changes

ROLLBACK TRAN



-- Report the error

SET @SQL = 'Error granting permission to ['

+ @Owner + '].[' + @StoredProcedure + ']'

RAISERROR(@SQL, 16, 1)

END

GO

View 3 Replies View Related

SQL Server 2012 :: How To Use Scalar Function Without WHILE

Jan 19, 2014

I have a scalar function, which calculates the similarity of two strings. I use the following query, to compare the entries of one table against the value 'Test' and return the entries, which have a value > 50:

;WITH cte1 AS (
SELECT b.FirstName,
(SELECT fn_similarity('Test', b.FirstName)) AS [Value],
b.LastName
FROM [AdventureWorks2012].[Person].[Person] b
)

SELECT *
FROM cte1
WHERE [Value] > 50.00
ORDER BY [Value] DESC

Now I want to use this query against the first 50 entries of the [Person] table, so that the resultset includes all the values of the first 50 persons and the entries, which are similar to them.

At the moment I use a WHILE-loop and write the five single resultsets in a temporary table. Is there another way / a better way, maybe via a join?

View 9 Replies View Related

How To Handle Error In Scalar Function?

Nov 28, 2007

Hi, I have the follow function:

CREATE FUNCTION [dbo].[ToTime]
(
@intHora int, --A valid hour
@intMin int -- A valid minute
)
RETURNS smalldatetime
AS
BEGIN
declare @strTime smalldatetime
declare @errorvar int

select @strTime=cast(convert(varchar,cast((cast(@intHora as varchar) +':'+ cast(@intMin as varchar)) as smalldatetime),108) as varchar)
return @strTime;
END

the function works perfect but when the parameter for the hour is a negative number (for example -1), or a number > 23
and the parameter for the minute is an negative number (-1) or a number > 59, the function produce an error.
I need handle this error converting the wrong value in 0, but i don't want to do this using "if statement". for example

if @intHora < 0 or @intHora >23
begin
set @intHora = 0
end
if @intMin <0 or @intMin>59
begin
set @intMin = 0
end

please, If someone know some sql function (try - catch doesn't work) to handle this kind of error or some good way to do it, please help me.

View 4 Replies View Related

T-SQL (SS2K8) :: Proper Use Of CTE In Scalar Valued Function?

Dec 1, 2014

I have troubles with this scalar-valued UDF:

I get the error:

Select statements included within a function cannot return data to a client.

Is this a proper way to include a CTE in a function?

USE [DB1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[_Pink_FN_StartingDatePLGeographical](@StartingDate AS DATETIME) RETURNS NVARCHAR(20)

[code].....

View 4 Replies View Related

Transact SQL :: Storing Parameter Value Used By Scalar Function

May 14, 2015

I've a scalar function which is killing my performance. I've been used the SQL profiler and also DMVs to catch execution information. I'd like to store the value received by this function and also the time that it happened, but I can't think in a way to do it.

View 5 Replies View Related

SOLVED: How To Call Scalar Function From JDBC

Jan 28, 2008

As an example, I have a scalar function called TRIM that takes a VARCHAR parameter, does a LTRIM(TRIM(VARCHAR)), and returns the result.

How can I call this function from java using JDBC? I have only had luck calling basic stored procedures, but I need to call functions as well.

Thanks, Ken

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved