- Home /

i need to create a function that gets 2 parameters an id of a customer and a price i have to calculate the age of the customer and depending on his age i have to calculate a discount on the price

so for the function i tried

CREATE FUNCTION DISCOUNT(@ID INT,@PRICE INT) RETURNS TABLE RETURN SELECT BIRTHDATE FROM CUSTOMER WHERE BIRTHDATE > '10-14-1955' SET @price = @price - 10

The problem is that i need to return a scalar value instead of a table but i don't know how to access the birthdate colomn within a scalar function

is there someone who can help me? thanks

Comment

**Answer** by Piotr Rodak ·

Something like this?

```
CREATE FUNCTION DISCOUNT(@ID INT,@PRICE INT)
RETURNS TABLE
RETURN
SELECT BIRTHDATE, @price - 10 as discountedPrice
FROM CUSTOMER
WHERE BIRTHDATE > '10-14-1955'
```

But what @ID has to do with this rowset?

**Answer** by Squirrel 1 ·

scalar function can only return 1 value. You want to return the birthdate and the price ?

Since both are not related, can you use 2 scalar function to do it ?

Copyright 2019 Redgate Software.
Privacy Policy

- Anonymous
- Sign in
- Create
- Ask a question
- Spaces
- Ask SSC Site Issues (meta-askssc)
- Explore
- Topics
- Questions
- Users
- Badges