hi guys
I have a user defined sql function in my sql server db called TenPercentDiscount but not sure how to call it within sql statement?
I'm ideally looking for my function to be applied to a select * sql statement similar to my amateur attempt below
iv tried both
"SELECT * FROM TenPercentDiscount(RMT_2DayTours) WHERE ID IN (1,2,3)"
"SELECT TenPercentDiscount, * FROM RMT_2DayTours WHERE ID IN (1,2,3)"
but not having any joy? my function code is -
CREATE FUNCTION TenPercentDiscount
-
(@InputVals int)
-
RETURNS int
-
AS
-
BEGIN
-
declare @convertedVal varchar(30)
-
set @convertedVal = Cast(@InputVals * 0.9 as int)
-
return @convertedVal
-
end
please advise
omar
4 3655
If RMT_2DayTours is a table then - SELECT TenPercentDiscount(field_from_RMT_2DayTours) As discounted
-
FROM RMT_2DayTours
-
WHERE ID IN (1,2,3)"
hi code green - yes RMT_2DayTours is a table. Is it bad practice to not include dbo. before a table name? if it is please let me know as I dont want to continue with bad habits.
I've tried your suggestion - SELECT TenPercentDiscount(Double_Redleaf_Price) as Double_Redleaf_Price
-
FROM RMT_2DayTours
-
WHERE ID IN (1,2,3)"
but im getting the following error
Microsoft OLE DB Provider for SQL Server error '80040e14'
'TenPercentDiscount' is not a recognized built-in function name.
please advise
The "dbo" prefix means the object you are calling is owned by dbo. If you have a lot of object (tables, SP, function) in your database that's owned by different users, they may or may not have the same name. To make sure you are calling, reading or executing the right object, the owner name is usually included. As rule of thumb, yes, you should use the owner.
In calling the function, SQL Server, more often than not, expects the owner's name. So do a dbo.TenPercentDiscount(Double_Redleaf_Price). To be very sure, put the database name in front.
Happy Coding!!!
~~ CK
Sorry about the missing dbo.
I should know better because my SQL Server will throw an error without the dbo
(similar to yours, strangely)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joel Thornton |
last post by:
Is it possible to call a user-defined function without prefixing it
with 'dbo.' within a SELECT clause somehow? Just curious; it's not a
big issue but just a stylistic one for me.
Thanks!
...
|
by: Steve D |
last post by:
I've looked all over but can't find a solid answer. I've got a
function that runs from a View and when the function runs the first
time it is calculating a Temperature for a group of Formulas. ...
|
by: Mountain Man |
last post by:
Hi,
I'm trying to use window.open from inside a user defined function, and
it's not working. A code example is shown below. Thanks for any help
you can give.
Mountain Man
============
...
|
by: Gary Besta |
last post by:
I am trying to add a simple case statement to a stored procedure or
user defined function. However when I try and save the
function/procedure I get 2 syntax errors. Running the query in query...
|
by: Maroon |
last post by:
Hi,
I want to write a standard java user defined function, like this
example:-
select db_fun("roll"), roll from student;
**db_fun() will work for all tables of the all databse
here db_fun is...
|
by: Mrs Howl |
last post by:
I have a query that just reads one table and appends to an output
table, one-for-one. No criteria. It's not a Total query (i.e. no
group by). It normally run run in minutes, but gets horribly...
|
by: Mphoza |
last post by:
Hi! Programmers,,,,,,
Scenario
I have a DataGrid with the delete button, If the user delete the row I'd
like to show a confirmation dialog box with two buttons(Yes,No). If the user
click yes...
|
by: Mahesh S |
last post by:
Hi
I want to write a user defined function which does the following.
1. Take a string value as input parameter
2. Should execute a sql statement: select col1, col2, col3, col4 from
table_name...
|
by: Mark B |
last post by:
I have been able to retrieve the scalar value of a SQL Server Stored
Procedure as follows:
Shared Function fGetGroupPerformanceStatistic(ByVal strGroup As String) As
String
Dim sqlConnection1...
|
by: qwedster |
last post by:
Hola!
In the following code snippet, I am creating User Defined Function (T-SQL) programmatically into database from C# Code:
BTW, this code originally I wrote for creating StoredProcedure...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |