Function For Return Element List From A Query

Aug 9, 2007

Hello,

I have do a sql function for return a list of element from a query send in variable.



When I test the function on self I have no problem.

But when I use the function in a sql query I have problem.

example :




Code SnippetSELECT APPLI_SUPPLIER.N_SUPPLIER_ID, APPLI_SUPPLIER.V_SUPPLIER_LABEL,
dbo.APPLI_RETURN_LIST_ITEM('SELECT DISTINCT APPLI_CONSTRUCTION.V_PROCESS_CODE FROM APPLI_CONSTRUCTION INNER JOIN APPLI_SUPPLIER_SKILL ON APPLI_CONSTRUCTION.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID WHERE (APPLI_CONSTRUCTION.V_PROCESS_CODE IS NOT NULL) AND (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2,3,4,5,6))')
AS V_PROCESS_ITEMS
FROM APPLI_SUPPLIER INNER JOIN
APPLI_SUPPLIER_SKILL ON APPLI_SUPPLIER.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID
WHERE (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2, 3, 4, 5, 6))






This is the error :

Server: Msg 557, Level 16, State 2, Procedure APPLI_RETURN_LIST_ITEM, Line 24
Only functions and extended stored procedures can be executed from within a function.



When I do an exec of the function I have this problem :



Code Snippet
exec APPLI_RETURN_LIST_ITEM('SELECT DISTINCT APPLI_CONSTRUCTION.V_PROCESS_CODE FROM APPLI_CONSTRUCTION INNER JOIN APPLI_SUPPLIER_SKILL ON APPLI_CONSTRUCTION.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID WHERE (APPLI_CONSTRUCTION.V_PROCESS_CODE IS NOT NULL) AND (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2,3,4,5,6))')


Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'SELECT DISTINCT APPLI_CONSTRUCTION.V_PROCESS_CODE FROM APPLI_CONSTRUCTION INNER JOIN APPLI_SUPPLIER_SKILL ON APPLI_CONSTRUCTION.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID WHERE (APPLI_CONSTRUCTION.V_PROCESS_CODE IS NOT NULL) AND (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2,3,4,5,6))'



This is the function



Code Snippet
CREATE FUNCTION [dbo].[APPLI_RETURN_LIST_ITEM]
(@QUERY AS VARCHAR(3900)=null)
RETURNS varchar(8000)
AS
BEGIN
-- Insert statements for procedure here
declare @v_List_ITEM as varchar(8000)
set @v_List_ITEM=''
if @QUERY is not null
Begin
declare @cur_Lect_ITEM CURSOR;
declare @FUNCTION AS NVARCHAR(4000);
Declare @ITEM as VARCHAR(255);
SET @FUNCTION = 'set @mainCursor=cursor for ' + @QUERY + ' for read only open @mainCursor'


EXEC sp_executesql @FUNCTION,N'@mainCursor cursor output', @cur_Lect_ITEM output
fetch next from @cur_Lect_ITEM into @ITEM
while @@fetch_status=0
begin
set @v_List_ITEM=@ITEM + ' ; ' + @v_List_ITEM
fetch next from @cur_Lect_ITEM into @ITEM
end
deallocate @cur_Lect_ITEM
SET @v_List_ITEM=REPLACE(REPLACE(@v_List_ITEM, CHAR(13), ''), CHAR(10), '')
set @v_List_ITEM=left(@v_List_ITEM,len(@v_List_ITEM)-3)
End
RETURN @v_List_ITEM
END


Can you help me please?
Thank you

View 11 Replies


ADVERTISEMENT

Return A Result Set From A SELECT Query In A Function?

Jan 21, 2008

Hello all:

How can I return the result of a SELECT statement from a stored procedure (function)?

CREATE FUNCTION returnAllAuthors ()
RETURNS (what do i put here??)
BEGIN

// Is this right??
RETURN SELECT * FROM authors

END


Thanks!

View 12 Replies View Related

Transact SQL :: Return A Query Based On Dateadd Function

Aug 3, 2015

I'm trying to return a query based on the dateadd function.  I have a column in the database called date_added which is am successfully using the the DATEADD function above as date1.  The Var1 variable I need to populate from the database too from a column called life_span which is an int data type.  The error I get is An expression of non-boolean type specified in context where a condition is expected near select

My query is as follows: select guid, dateadd(day,life_span,date_added) as datepayday. From User_table

View 5 Replies View Related

'Return' Statement In A Function,Get,or Operator Must Return A Value....Question

Aug 28, 2007


I'm a Reporting Services New-Be.

I'm trying to create a report that's based on a SQL-2005 Stored Procedure.

I added the Report Designer, a Report dataset ( based on a shared datasource).

When I try to build the project in BIDS, I get an error. The error occurs three times, once for each parameter on the stored procedure.

I'll only reproduce one instance of the error for the sake of brevity.

[rsCompilerErrorInExpression] The Value expression for the query parameter 'UserID' contains an error : [BC30654] 'Return' statement in a Function, Get, or Operator must return a value.

I've searched on this error and it looks like it's a Visual Basic error :

http://msdn2.microsoft.com/en-us/library/8x403818(VS.80).aspx

My guess is that BIDS is creating some VB code behind the scenes for the report.

I can't find any other information that seems to fit this error.

The other reports in the BIDS project built successfully before I added this report, so it must be something specific to the report.

BTW, the Stored Procedure this report is based on a global temp table. The other reports do not use temp tables.

Can anyone help ?

Thanks,

View 5 Replies View Related

Query Out An Xml Element From A Field Containing Xml Data

Jan 26, 2006

'message' Field Data:<xml>....<test>ABC</test>....</xml>How do I query out 'ABC' from this xml field data in a SQL Server?Assume message field is in table 'Persons'

View 3 Replies View Related

SSIS- The Element Cannot Be Found In A Collection. This Error Happens When You Try To Retrieve An Element From A Collection On A

May 19, 2008

hi,

this is sanjeev,
i have SSIS package, using my c# program i want to add one execute package task to this package's sequence container.


it is creating the new package with out any probelm. but when i opened the package and try to move the newly created exeute package task it is giving the following error.


the element cannot be found in a collection. this error happens when you try to retrieve an element from a collection on a container during the execution of the package



this is my code



{
Package pkg = new Package();
string str = (string)entry.Key;
pkg.Name = str;
alEntity = (ArrayList)entry.Value;

ConnectionManager conMgr;
Executable chPackage;
TaskHost executePackageTask;

Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();



//string PackagePath = @"c:Genesis.dtsx";

//p = app.LoadPackage(PackagePath, null);
p = new Package();
p.LoadFromXML(parentPackageBody, null);


p.Name = str;

//Sequence seqContainer;

IDTSSequence seqContainer;
//seqContainer = (Sequence)p.Executables["Extract Genesis Data"];
seqContainer = ((Sequence)p.Executables[0]);

string packageLocation = @"Geneva Packages";
conMgr = p.Connections["SQLChildPackagesConnectionString"];






foreach (string val in alEntity)
{
if (seqContainer.Executables.Contains("Load_" + val) == false)
{
chPackage = seqContainer.Executables.Add("STOCK:ExecutePackageTask");



executePackageTask = (TaskHost)chPackage;
executePackageTask.Name = "Load_" + val;
executePackageTask.Description = "Execute Package Task";


executePackageTask.Properties["Connection"].SetValue(executePackageTask, conMgr.Name);
executePackageTask.Properties["PackageName"].SetValue(executePackageTask, packageLocation + ddlApplication.SelectedItem.Text + @"" + executePackageTask.Name);



}
}


app.SaveToXml(Server.MapPath("../SynchronizeScript/Packages/" + ddlApplication.SelectedItem.Text + @"") + str + ".dtsx", p, null);
}






please let me know what is the wrong in my code.

thanks in advance.

regards
sanjeev bolllina
sanjay.bollina@gmail.com

View 14 Replies View Related

Return Value Of Empty List

Aug 15, 2006

Hi,

I'm trying check the records which satisfies the following condn.

select @p1 = su1 from RER where (no=10 and atp ='N')

It returns empty list . bcos no match found.that's ok.

But i need to write the logic if record is not there.

i tried to do as follows

if ((@p1 =null) or (p1=' '))

...some logic

else

.. other logic

It's always executing else case. How do i catch empty value using sql query.

Is there any command there like null?

I tried in SQL query analyzer. Using SQL 2000.

Thank You

View 6 Replies View Related

Return Only The Rows From A List That Has The Same Value From One Field

Aug 2, 2006

I am in need of help to develop a query
I have two tables Exams and Exams_lab, that are joined by a field id_exame. I want to return The Exams that has all the dependent rows in Exames_lab with the same value in the status_int field of Exames_lab. Can anyone Help Me?
Lets see an example
tb_exame



id_exame
date_exame

1
07/01/2006

2
08/01/2006

3
09/01/2006
tb_exame_lab



id_exame_lab
id_exame
desc_exame
status_exame

1
1
NORMAL
1

2
1

0

3
2
NORMAL
1

4
2
PROBLEMS
1

5
2
OK
1

6
3
OK
0
in this exemple my query must return only id_exame 2 and 3 because id_exame 1 has two different values on id_status on tb_exame_lab
can anyone help me?
 

View 5 Replies View Related

How To Return A List Of Empty Tables

Mar 19, 2003

I want to return a list of user tables from a database where the rowcount is 0. This will be a 3 step process: (1) truncate all 'New%' tables, (2) load data via ODBC/DTS into 'New%' tables, (3) list all 'New%' tables with zero rows (i.e. those that didn't get loaded, as all tables in the ODBC data source contain data).

I've tried:
select left(s2.name,32) as TableName, max(s1.rows) as Records
from sysindexes s1
inner join sysobjects s2 on s1.id=s2.id
where type = 'U' and s2.name like 'New%'
group by s2.name
HAVING max(rows) = 0
ORDER BY TableName
but of course there are multiple rows in sysindexes and the routine does not reliably return the correct list; for example the data in sysobjects & sysindexes, without the max and group by, might look like:
TableNameRows
NewARTxn0
NewARTxn1214800
NewARTxn1214800
NewARTxn1214800
NewARTxn1214800
NewARTxn1214800
NewARTxn1214800
I was hoping to come up with a single T-SQL statement that I could use in an xp_sendmail situation to email me the results.

Thanks for the suggestions.

Al

View 3 Replies View Related

Items In List A That Don't Appear In List B (was Simple Query...I Think)

Jan 20, 2005

Ok, I want to write a stored procedure / query that says the following:
Code:
If any of the items in list 'A' also appear in list 'B' --return false
If none of the items in list 'A' appear in list 'B' --return true


In pseudo-SQL, I want to write a clause like this

Code:

IF
(SELECT values FROM tableA) IN(SELECT values FROM tableB)
Return False
ELSE
Return True


Unfortunately, it seems I can't do that unless my subquery before the 'IN' statement returns only one value. Needless to say, it returns a number of values.

I may have to achieve this with some kind of logical loop but I don't know how to do that.

Can anyone help?

View 3 Replies View Related

SQL 2005 Return A List Of Missing Rows By Date?

Feb 12, 2008

Hi,

I have written a reporting application which has a SQL2005 backend. An import routine into SQL, written by a 3rd party, frequently fails. The main problems are missing rows in certain tables.

I am going to write an SP that will accepts a from and to date. I then want to search for rows of type X between those dates that do not exist so we then know between a date range, we have no data for these XYZ days.

I have this working by returning all rows between the dates into a dataset, sorted by date, and then running through the rows and testing if the next rows date is the next expected date. This works but I think is a very poor solution. This is all done on the client in C#.

I want to learn and implement the most efficent way of doing this. My only solution in a SP was to make a temporary table of all dates between the date range for row type X and then do a right outer join against the data table, returning all rows which are missing.

Something like this:

SELECT twmd.date
FROM #temp_table_with_all_dates ttwad
RIGHT OUTER JOIN table_with_missing_date twmd
ON ttwad.date = twmd.date
WHERE twmd.date IS NULL

Would this be a good, efficent solution, or should I just stick to my processing of a dataset in C#?

Many thanks in advance,
CB

View 4 Replies View Related

Return A List Of New Tables Or Columns Which Do Not Exist In A Database

Mar 24, 2008



What SQL statement can i run to return a list of new tables or columns that exist in the Sales Database on Server A, which do not exist in the Sales Database in Server B.

Server A and Server B are linked servers.

I am using SQL Server 2005. Thanks.

View 1 Replies View Related

List Function

Aug 8, 2000

Converting Sybase to SQL Server !

On the Sql Server's database I did :

-- test list function with cursor
alter proc proc_list(@key varchar(255), @retlistvalues varchar(8000) output)
as
declare @incrcurs2 cursor
declare @value varchar(255)
declare @listvalues varchar(8000)
set @incrcurs2 = cursor scroll dynamic
for
select t.title_Id from publishers p, titles t where p.pub_id = t.pub_idand p.pub_id = @key
order by t.pub_id
open @incrcurs2
fetch next from @incrcurs2 into @value
select @listvalues = convert(varchar(255),@value)
WHILE @@FETCH_STATUS = 0
begin
select @listvalues = @listvalues + ',' + convert(varchar(255),@value)
fetch next from @incrcurs2 into @value
end
CLOSE @incrcurs2
DEALLOCATE @incrcurs2
select @retlistvalues = @listvalues
go
declare @listvalues varchar(8000)
execute proc_list '1389',@listvalues output
print @listvalues

With Sybase, easily :
Select t.pub_id, list(t.title_Id) from publishers p, titles t where p.pub_id = t.pub_id
And I 've got all the titles in a comma-separated string by publisher !!!!

So, with SQL Server, I suppose that if I want the result by publisher, I must imbricate two cursors !!!

Perhaps I dream
Or can somebody see a better solution ????
Thanks

Axel Thimonier

View 1 Replies View Related

List Function

Nov 21, 1999

I've recently read in Joe Celko's "SQL For Smarties" book that there is a LIST() function in Sybase's SQL Anywhere that will aggregate string data into a single comma separated column.

Unfortunately, this command is not supported in T-SQL. Does anyone know how to achieve a similar result with conventional SQL, where I want to aggregate string data into a single column.

Here's my task. Say I have two tables, tParents and tChildren, a parent has many children. I want a sql statement that returns one row for each parent and the multiple children associated to each in a single comma separated column, i.e

Joe Blow 'Child1, Child2, ...'
Parent2 'Child4, Child5, ...'

The SQL with this LIST() function would look like:

Select Parent, List(tChildren.Child) as Children
From tParents, tChildren
Where tParents.PID = tChildren.CID
Group By Parent


Thanks in advance for any help.

Cheers,
Steve Roch
Research Systems, Inc.
stever@rsinc.com

View 2 Replies View Related

List Function

Sep 4, 2007

In sybase, there is function List, which joins few records in one cell. Is there any function, who does it in MS SQL?

View 14 Replies View Related

Using Parameter (@value) For IN Function List

Jul 20, 2005

I am trying to select a group of records based on a parameter valuepassed to the db from a web page. The value comes in as @Status andhas a list of statusID's: (1,2,5,9) I've tried to use"Where table.status IN (Select * from @Status AS ValueList)"And also tried"Where table.status IN (@Status)"And neither worked. Any suggestions?

View 2 Replies View Related

Getting A Return Value From A Function.

Oct 6, 2005

Im a self proclaimed newb and Im stuck on returning a value from a function. I want to get the AttendID that the SQL statement returns and dump it into strAttendID: Response.Redirect("ClassSurvey.aspx?Pupil=" & strAttendID)I cant seem to accomplish this. It returns nothing. Please help.TIA,Stue<code>Function Get_AttendID(ByVal strAttendID As String) As SqlDataReaderDim connString As String = ConfigurationSettings.AppSettings("ClassDB")Dim sqlConn As New SqlConnection(connString)Dim sqlCmd As SqlCommandDim dr As SqlDataReader
sqlConn.Open()Dim strSQL As String = "Select AttendID from attendees Where FirstName=@FirstName and LastName=@LastName and classbegdt = @classbegdt and survey = '0'"
sqlCmd = New SqlCommand(strSQL, sqlConn)
sqlCmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50)sqlCmd.Parameters("@FirstName").Value = tbFirstName.TextsqlCmd.Parameters.Add("@LastName", SqlDbType.VarChar, 50)sqlCmd.Parameters("@LastName").Value = tbLastName.TextsqlCmd.Parameters.Add("@classbegdt", SqlDbType.DateTime, 8)sqlCmd.Parameters("@classbegdt").Value = calBegDate.SelectedDate.ToShortDateStringdr = sqlCmd.ExecuteReader()dr.Close()sqlConn.Close()
Return dr
End Function</code>

View 4 Replies View Related

Function Return Value

Jun 13, 2004

I want to write a function that returns the physical filepath of the master database for its MDF and LDF files respectively. This information will then be used to create a new database in the same location as the master database for those servers that do not have the MDF and LDF files in the default locations.

Below I have the T-SQL for the function created and a test query I am using to test the results. If I print out the value of @MDF_FILE_PATH within the funtion, I get the result needed. When making a call to the function and printing out the variable, all I get is the first letter of the drive and nothing else.

You may notice that in the function how CHARINDEX is being used. I am not sure why, but if I put a backslash "" as expression1 within the SELECT statement, I do not get the value of the drive. In other words I get "MSSQLData" instead of "D:MSSQLData" I then supply the backslash in the SET statement. I assume that this has something to do with my question.

Any suggestions? Thank you.

HERE IS T-SQL FOR THE FUNCTION
IF OBJECT_ID('fn_sqlmgr_get_mdf_filepath') IS NOT NULL
BEGIN
DROP FUNCTION fn_sqlmgr_get_mdf_filepath
END
GO

CREATE FUNCTION fn_sqlmgr_get_mdf_filepath (
@MDF_FILE_PATH NVARCHAR(1000)--Variable to hold the path of the MDF File of a database.
)
RETURNS NVARCHAR
AS

BEGIN

--Extract the file path for the database MDF physical file.
SELECT @MDF_FILE_PATH = SUBSTRING(mdf.filename, CHARINDEX('', filename)+1, LEN(filename))
FROM master..sysfiles mdf
WHERE mdf.groupid = 1

SET @MDF_FILE_PATH = SUBSTRING(@MDF_FILE_PATH, 1, LEN(@MDF_FILE_PATH) - CHARINDEX('', REVERSE(@MDF_FILE_PATH)))

RETURN @MDF_FILE_PATH

END



HERE IS THE TEST I AM USING AGAINST THE FUNCTION
SET NOCOUNT ON

DECLARE
@MDF_FILE_PATH NVARCHAR(1000)--Variable to hold the path of the MDF File of a database.

SELECT @MDF_FILE_PATH = dbo.fn_sqlmgr_get_mdf_filepath ( @MDF_FILE_PATH )
PRINT @MDF_FILE_PATH

View 11 Replies View Related

Sybase List Function With Sum With Server?

Mar 2, 2014

I have a subquery that retunrns multiple lines. To solve it, I have used the List function. The separation of List function is comma.

TblBill is in the main query with many other tables.
(Select List(tblBatch.batchnr) From tblBatch where tblBatch.tr_id = tblBill.kfr_trans_id ) As Batchnr

This subquery returns: B12, B13, B14, B43 and so on...

Now I want to use SUM from another field (quant) from table tblBatch in the subquery and then separate those with a line break instead of comma. Batch number may occur several times and I want to summarize these

I want the subquery return like this:

---Batchnr---
3 B12
4 B13
1 B14
1 B43

and so on..

How do I solve it the best way with SQL Server?

View 3 Replies View Related

Return @@identity For Another Function

May 14, 2004

What I'm trying to do is provide a solution where users can upload an image and a description, to a database, so I'm trying to insert the title and description then return the @@identity for the image upload function which will name the image like this
image_23.jpg (23 being the @@identity) resize it and save it to specified directory

I cant seem to get the identity to return to my script.
This is my SP

CREATE PROCEDURE SP_Insertad
(
@catid int,
@subcatid int,
@areaid int,
@uid int,
@adtitle varchar(255),
@addescription varchar(1000)
)

AS
Insert Into Tbl_ad
(ad_title, ad_description,ad_area,ad_ui_id,ad_active,ad_date,ad_ct_id,ad_sc_id,ad_location)
VALUES
(@adtitle,@addescription,@areaid, @uid, 0,convert(varchar, GETUTCDATE(), 101), @catid, @subcatid, 1)

select @@identity
return
GO


I tested in query analyser, and it works fine, so It must be my code. this is my function

Sub Insert_pic(sender as object, e as eventargs)

Dim catid = Request.form("ddcats")
Dim subcatid = Request.form("subcatrad")
Dim adtitle = Request.Form("txttitle")
Dim AdDescription = Request.form("txtdescription")
Dim uid = getUID(Context.User.Identity.Name)
Dim areaid = Request.form("ddarea")
SQLConnect = new SqlConnection(ConfigurationSettings.Appsettings("mydB"))

SQLCommander = New SQLCommand("SP_INSERTad", SQLConnect)

SQLCommander.Commandtype = Commandtype.StoredProcedure

SQLCommander.Parameters.add("@adtitle", adtitle)
SQLCommander.Parameters.add("@addescription", addescription)
SQLCommander.Parameters.add("@catid", catid)
SQLCommander.Parameters.add("@subcatid", subcatid)
SQLCommander.Parameters.add("@uid", uid)
SQLCommander.Parameters.add("@areaid", areaid)

'// this section not working right, it wont write return id

Dim paramreturn as SQLParameter
paramreturn = SQLCommander.Parameters.Add("ReturnValue", SQLDBType.Int)
ParamReturn.Direction = ParameterDirection.ReturnValue

response.write(SQLCommander.Parameters("ReturnValue").Value)

SQLConnect.open()
SQLCommander.ExecuteNonQuery()
SQLConnect.close()

End sub

Can anybody see anything I missing? I appreciate any imput

View 4 Replies View Related

I Need The Function To Return A Srting

Jul 21, 2004

Hii every one
When i use the function of (select) from the data bass it return dataset or some thing else
But I need it to return string or the data element which in the query not all the query

like

I dont need that
_____________
| Id | Name |
-----------------
| 1 | Bill |
--------------------
I dont need All of that to display But I need to display the name only in Label or textbox
like
Bill

Thanks
Maro

View 3 Replies View Related

How To Return 0 Instead Of Null When Using A Sum Function?

May 10, 2005

Hi,
I basically do not want to return a null value as a result of using a sum function (using sum against 0 rows).
Is there a common way to avoid this?
Thanx

View 5 Replies View Related

Table Return Function

Feb 14, 2008

Dear all,
can i write a table return function like this?

create function my_function(
returns @MYTABLE table(NAME VARCHAR(20),SES VARCHAR(20),CNT DECIMAL(10),MYDATE DATATIME)
insert into @mytable
select col1,col2,col3,col4 from tab1
go
select col1,col2,col3,col4 from tab2
go
select col1,col2,col3,col4 from tab3
go
select col1,col2,col3,col4 from tab4
go
return
end


am i doing correct?
what i'm expecting from this function is, i need all the data from select statements should be inserted into one table.
please guide me in this regard


Vinod
Even you learn 1%, Learn it with 100% confidence.

View 3 Replies View Related

Why My Function Wont Return The Value

Mar 9, 2008

//this is the function
double sem_3 ( double gpa_sem_1, double gpa_sem_2 )
{
int back_3;
char grade [2];
double score = 0;
double gpa_sem_3;
double cgpa_sem_3;

double problem_solving_and_programming;
double fundamentals_of_finance;

printf("FCCS1013 Problem Solving and Programming : ");
scanf("%s",&grade );
score = grade_selection( grade );
problem_solving_and_programming = score * 3;

printf("FBFF1013 Fundamentals of Finance : ");
scanf("%s",&grade );
score = grade_selection( grade );
fundamentals_of_finance = score * 3;

gpa_sem_3 = ( ( problem_solving_and_programming + fundamentals_of_finance ) / 6 );
cgpa_sem_3 = ( ( gpa_sem_1 + gpa_sem_2 + gpa_sem_3 ) / 3 );

printf("GPA = %.4f", gpa_sem_3);
printf("CGPA = %.4f", cgpa_sem_3);

printf("press 0 to go back to option menu: ");
scanf("%d", &back_3);

if( back_3 == 0 )
{
system("cls");
main();
}
else
{
printf("invalid option ");
}

return gpa_sem_3;
}
--------------------------------------------------------------------------------------------------------------------------------------------
//this is the main program(part of it only)

case 1:

system ( "cls" );
gpa_sem_1 = sem_1( );

break;
--------------------------------------------------------------------------------------------------------------------------------------------------
// why doesn't the error promp when the user enters an invalid entry? in the codes below.

double grade_selection ( char grade[] )
{

double score = 0;

if (strcmp( grade, "A+" ) ==0 || strcmp( grade, "a+" ) == 0)
{
score += 4.00;
}
else if (strcmp( grade, "A-" ) == 0 || strcmp( grade, "a-" ) == 0 )
{
score += 3.70;
}
else if (strcmp( grade, "B+" ) == 0 || strcmp( grade, "b+" ) == 0 )
{
score += 3.30;
}
else if (strcmp( grade, "B" ) == 0 || strcmp( grade, "b" ) == 0 )
{
score += 3.00;
}
else if (strcmp( grade, "B-" ) || strcmp( grade, "b-" ) == 0)
{
score += 2.70;
}
else if (strcmp( grade, "C+" ) || strcmp( grade, "c+" ) == 0 )
{
score += 2.30;
}
else if (strcmp( grade, "C" ) || strcmp( grade, "c" ) == 0 )
{
score += 2.00;
}
else if (strcmp( grade, "D" ) || strcmp( grade, "d" ) == 0 )
{
score += 1.00;
}
else if (strcmp( grade, "F" ) || strcmp( grade, "f" ) == 0 )
{
score += 0.00;
}
else
{
printf( "invalid grade" );
printf( "please enter again: " );
getchar( grade[2] );
}

return score;

}
-------------------------------------------------------------------------------------------------------------
thanks.

View 1 Replies View Related

How To Return Varchar(MAX) From A CLR Function?

May 23, 2006

Hi,

I am trying to return [string/SqlString] from a CLR function, but it was truncated at 8000 characters.

How can I solve this problem and return varchar(MAX)?

Thanks

View 5 Replies View Related

Catch The Return Value From A Function

May 17, 2008

Hi guys!

the problem is this:

I have a procedure that execute a function and i want to catch the return function value but i'm getting a null value.

I'm using:

exec @a = <function>


but the @a variable is allways null...



If i exec the function directly, i get the correct value.



What am i doing wrong?

Thanks in advance.

View 10 Replies View Related

Question Regarding A Function Return

Apr 7, 2008

I have a function that is using a select case decision structure to arrive at a return value:


[dbo].[fn_Window]

(@Start AS INT,

@End AS INT) RETURNS VARCHAR(5)

AS

BEGIN

SELECT

CASE

/*** Pick up the extended periods here ***/

WHEN @Start = 1 AND @End = 1 THEN 'TRUE'
ELSE 'FALSE'
END

END

**** from here how do I get the function to return true or false? ****
Can I assign the select case result to a variable? If so how?

View 4 Replies View Related

Multi-Select On List View - Return InstructorID Where ClassID Matches All Of ClassIDs In String

Nov 19, 2012

I have a list of ClassID that is stored based on users multi select on a listview

For example ClassID might contain

301
302
303
304

Now I need to find InstructorID where classID matches all the value in the above list.

I am using this query

Code:
Dim assSQL = "Select InstructorID from ClassInstructors where ClassID = @P0"
For i = 1 To classIDs.Count - 1
assSQL &= " UNION Select InstructorID from ClassInstructors where ClassID = @P" & i.ToString
Next

[Code] ....

But the problem is the query is returning InstructorID where ClassID matches any of the ClassIDs. I want it to return Instructor ID where ClassID matches all of the ClassIDs in the string.

View 1 Replies View Related

Can A Sql 2005 Function Return More Than A Variable

Jul 30, 2007

Hi,I have a sql 2005 function who return a distance from 2 zipcodes. This function is called from a Stored procedure like this :SELECT *, dbo.fn_GetDistance (...) AS DistanceIn this function, i have a Latitude and i want this Latitude to be also returned.It is possible or a function can return only one variable?If it is possible, what's the syntax of it?Thanks in advance

View 3 Replies View Related

MS SQL Function Return String - What Am I Doing Wrong?

Jun 6, 2005

Cannot see where I am going wrong. I always get a value of 0. I know my function works correctly, so it must be the VB.


CREATE FUNCTION [dbo].[getNextProjectID] ()
RETURNS varchar(10) AS
BEGIN
'''''''''''''''''''...........................
DECLARE @vNextProjectID varchar(10)
RETURN @vNextProjectID
END


Sub LoadNextProjectNumber()
        Dim vProjectID As String
        Dim cmd As New SqlClient.SqlCommand()
        cmd.Connection = sqlConn
        cmd.CommandText = "getNextProjectID"

        cmd.Parameters.Add("@vNextProjectID", vProjectID)
        cmd.Parameters("@vNextProjectID").Direction = ParameterDirection.ReturnValue

        cmd.ExecuteScalar()
        vProjectID = cmd.Parameters("@vNextProjectID").Value

        txtProjectID.Text = vProjectID

        cmd.Dispose()
End Sub

View 4 Replies View Related

Return Multiple Values From A Function

Jun 19, 2007

searched all over, couldn't find a solid answer...is it possible to return multiple values from a sql function with sql server 2005?

e.g., I want to do this:

select id, data, whatever, dbo.fnMyFunction(id, whatever) from table

and have the output have columns (id, data, whatever, col1, col2) where col1 and col2 are returned by fnMyFunction

possible? easier way? thanks in advance...

View 4 Replies View Related

Function To Return Greater Of Two Numbers

Jun 2, 2008

Greetings,

Is there anything new on returning max of two values in SQL 05? There seems to be nothing I have searched everywhere. Only option might be to create my own UDF or do a CASE statement, but I could not believe my eyes there is no such thing?

Thanks

View 1 Replies View Related

Return 4 Output From A Function In Sqlserver

Jun 16, 2008

Hi I need a function which gets 3 parameters and input and returns 4 integers as output.
I don't know how to return 4 integers as output
any idea is appreciated.

View 7 Replies View Related







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