473,378 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

possible to use @variable in function?

when using the following code in my function, I'm getting errors. Is it possible to set a variable and then use it in a function as follows?

if OBJECT_ID ('tvf_Inline_Test') is not null
drop function tvf_Inline_Test
go
create function tvf_Inline_Test(@vstrDate char(15),
@VSTRDTYR char(15),
@mydatevar char(15),
@thismo as char(15))
set @thismo = right ('00' + CAST(DATEPART(Month, getdate()) AS VARCHAR(2)),2)
set @vstrDate = right ('00' + CAST(DATEPART(Month, getdate())-7 AS VARCHAR(2)),2)
--set @VSTRDTYR = CAST(DATEPART(YYYY, GETDATE()) AS VARCHAR(4))
SELECT @VSTRDTYR =
CASE
WHEN @thismo = 12 THEN CAST(DATEPART(YYYY, GETDATE())-1 AS VARCHAR(4))
ELSE CAST(DATEPART(YYYY, GETDATE()) AS VARCHAR(4))
END
set @mydatevar = LTRIM(RTRIM(@VSTRDTYR)) + '/' + LTRIM(RTRIM(@vstrDate))
returns table
as
return select wellID,yearmonth
from well_summary where well_summary.yearmonth = @mydatevar
go
Dec 27 '10 #1
1 1501
gpl
152 100+
yes you can, but you cannot use getdate() in a function
add another param and pass getdate()in that, then every reference within the function to getdate() should refer to the parameter value
Dec 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Thomas Herger | last post by:
Hi @ all I want to write the start of an function like this: $a . test($b) Is this possible? Is it possible to load diffrent functions with the same name from diffrent modules? How do I write...
6
by: Eddie | last post by:
I found it's not possible. But if I have a function which is called by every forms, do I have to copy the function to every form class? It looks like non-sense. Is there any other options?
3
by: Frank Teunen | last post by:
I have an VB.net application with very much funtions. These functions are autorised per user in a database table. In the main window I show all functions for the current user. If the user...
3
by: rwise5 | last post by:
I have been tasked with finishing the following C program. I need to develop the sort by birthday function and the print grade function. I have been working on the print function for the last week...
4
by: sorry im noob | last post by:
I'm trying to use a variable (as string) within criteria for DCount. I searched and found that you can't, and that instead I would need to write a one line function to return that same value. 1)...
3
by: not_a_commie | last post by:
Does MS have an official C# variable/function/codingstyle standard that is available on the internet? What standard do they use for their internal coding? Mind posting a link? Thanks.
0
by: hastha23 | last post by:
Dear Friends, My oracle Version is 10g. I calling a function from sql select same time function body contain DML statement,that time is possible call function from sql? and again one, ...
6
by: John | last post by:
Hi I have a function that needs to return value from some column in a table. The column type is not known in advance. Is it possible for function to return a value whose type would be determined...
7
by: TkNeo | last post by:
I don't know the exact terminology in python, but this is something i am trying to do i have 3 functions lets say FA(param1,param2) FB(param1,param2) FC(param1,param2) temp = "B" #something...
2
by: ritesh247 | last post by:
Hey, I am doing a project on one of my modules and I am supposed to build a function that gives uniform random variable between lets say Y and Z...I was wondering how this function can be built?? ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.