473,383 Members | 1,997 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,383 software developers and data experts.

simple problem with a table value function

JnrJnr
88
Expand|Select|Wrap|Line Numbers
  1. create function OutstandingBooks()
  2. returns table
  3. as
  4. BEGIN 
  5.  
  6. declare       
  7.         @TodaysDate date = getdate(),
  8.         @CountStart int = 1,
  9.         @CountRows int,
  10.         @ReturnDate date,
  11.         @Name varchar (50)
  12.  
  13.  
  14. select @CountRows = count (rows) +1 from SignOut_TM
  15. while (@CountStart <> @CountRows)
  16. begin
  17. select top (@CountStart) @ReturnDate = ReturnDate from SignOut_TM
  18.                 if (@TodaysDate > @ReturnDate)
  19.                 begin
  20.                 select @Name = EmployeName from SignOut_TM where ReturnDate = @ReturnDate
  21.                 end
  22. return select EmployeeName,CourseName,BookName,TodaysDate where EmployeeName = @Name
  23.     set @CountStart += 1            
  24. end
  25. END
I get the error - incorrect syntax near the word "begin"
what am I dong wrong?
Dec 2 '10 #1
2 1383
ck9663
2,878 Expert 2GB
Here's the syntax for CREATE FUNCTION. Check some of the samples.

Also, you can not assign variable and assign a value at the same time.

Good Luck!!!

~~ CK
Dec 2 '10 #2
JnrJnr
88
ah thanx, but I got it right to what I wanted.
Instead of going through all the rows one by one (like I did) I just had to get all my "returnDates" that are smaller than my "TodaysDate" and return the required data like this

Expand|Select|Wrap|Line Numbers
  1. create function OutstandingBooks
  2. ()
  3. returns @MyTable table
  4. (
  5. EmployeName varchar (50),
  6. CourseName varchar (50),
  7. BookName varchar (50),
  8. TakenDate date
  9. )
  10. as
  11. BEGIN 
  12.  
  13. declare       
  14.         @TodaysDate date = getdate(),
  15.         @CountStart int = 1,
  16.         @ReturnDate date
  17.  
  18. insert @MyTable select EmployeName,CourseName,BookName,TakenDate from SignOut_TM where @TodaysDate > ReturnDate 
  19.                 set @CountStart += 1
  20.  
  21. return   
  22. END
  23. go
  24.  
  25. select * from dbo.OutstandingBooks()
  26. go
Dec 7 '10 #3

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

Similar topics

6
by: Bob M | last post by:
Hi all, I am trying to update a record with a function value. Here is the function: update ITSM_SER_CUSTOM_FIELDS set SCF_SCDATE2 = SLA_PENDING_DATE.GET_DL(2292,'servicecall') where...
2
by: Bruce Lester | last post by:
Is there a way to create a trigger directly on an inline or multi-line table value function? I am trying to create a quick-and-dirty application using an Access Data Project front-end with SQL...
4
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input...
1
by: allyn44 | last post by:
Hello--i have inherited a dataset that has records like below: id locationid 1 7 2 3 5 4 5 6 4
3
by: Rob Rogers | last post by:
I have an ASP.NET datagrid that loads an image. I would like to load one image if the value in my SQL table is true and another if it is false. Here is my code. <%@ Page Language="vb"...
3
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table)...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
22
by: DL | last post by:
Hi, What I wanted to do is to call a function from a newly created element. But it stumbled me. Here's the line that references the newly created element and I used the alert function for...
4
Claus Mygind
by: Claus Mygind | last post by:
I understand how to link an element that exists on the form with a prototype function or class. But how do I link/bind a dynamically created element with the same prototype function or class In...
12
by: bcogan6502 | last post by:
I am using a form to display/edit some records from a table query. I can get the value I want to display, but I want to use a combo box that has a list loaded from another table to edit the field,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.