Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Tuesday, March 27, 2012

Database space available error

i am getting incorrect value while trying to retrieve space available ina database using sql dmo..

i am using sql server express 2005

Hard to help you without knowing the code you are using. Please post it here in order to help you. What are you getting back, what are you expecting ? Why are you expecting this value and not the actual presented by DMO ?


Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

databaseobject->get_spaceavailable(&space);

when i check this value with original value .ie. value known by opening database management is diferent

Sunday, March 11, 2012

database return issue

Hello all!

I have a stored procedure that I want to return a value to a C# varaiable:

Code:

public decimal GetSiloLevelForDate(string plantId, DateTime date)
{
decimal total = 0.0M;
Open();

SqlCommand cmd = new SqlCommand("getSiloLevelForDate", DbConn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@.plantId", plantId);
cmd.Parameters.Add("@.date", date);

SqlDataReader reader = cmd.ExecuteReader();

if (reader.Read())
{
if (!reader.IsDBNull(0))
total = reader.GetDecimal(0);

}
reader.Close();

Close();
return total;
}


this would normally work just fine. However, it is not becuase the actual SP's end statement is:

return (select @.tempTotal)

which should return a value. But it doesnt... if I run this SQL query:

declare @.usedTonnes numeric(13,2)
exec @.usedTonnes = dbo.getSiloLevelForDate ' 11', @.date

@.usedTonnes is a value, its 7096...

So why doesnt the C# return a value?

(so, the reader is not reading anything)Return values from stored procedures are typically used to indicatesuccess or failure, not to communicate data. A resultset or anoutput parameter is better/typically suited for this task.

The way I see it, you have 3 options:

1. Change your C# code
The way to access the return value is via a parameter with ParameterDirection = ReturnValue. You should beperforming an ExecuteNonQuery, and capturing this parameter. The datareader is overkill for what you are doing.

2. Change your stored procedure
instead of :
return (select @.tempTotal)
use:
select @.tempTotal
return
This would allow you to continue to use the datareader.

3. Change your C# code AND your stored procedure code
The way I'd suggest would be to change @.usedTonnes to an outputparameter in your stored procedure instead of a variable. In yourcode, you should beperforming an ExecuteNonQuery, and capturing this outputparameter with a parameter whose ParameterDirection = Output.

SeeInput and Output Parameters, and Return Values for more background information.|||

return(SELECT @.tempTotal) isn't correct.

The return from a stored procedure is a int. You are trying to passback a resultset through the return statement.

In addition your code is looking for a resultset not passed back from return.

Change your stored proc to end in:

SELECT @.tempTotal

return

and you won't have to change your C# code.

|||thanks for the tips guys. I did use the direction method to solve the issue:

SqlCommand cmd = new SqlCommand("getSiloLevelForDate", DbConn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@.plantId", plantId);
cmd.Parameters.Add("@.date", date);

SqlParameter param = cmd.Parameters.Add("@.tempTotal", SqlDbType.Decimal);
param.Direction = ParameterDirection.ReturnValue;

cmd.ExecuteNonQuery();

total = (int)param.Value;

worked fine, and the SQL was

if( @.tempTotal is not null) begin
return @.tempTotal
end
else begin
set @.tempTotal = 0
return @.tempTotal
end

and i got the correct result|||I did end up having to use the direction method of the SqlCommand object:

SqlCommand cmd = new SqlCommand("getSiloLevelForDate", DbConn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@.plantId", plantId);
cmd.Parameters.Add("@.date", date);

SqlParameter param = cmd.Parameters.Add("@.tempTotal", SqlDbType.Decimal);
param.Direction = ParameterDirection.ReturnValue;

cmd.ExecuteNonQuery();

total = (int)param.Value;

Friday, February 24, 2012

Database Recovery Model Default value

Hi
I've been using SQL Server 2000 for quite some time. Every new database I
used to add, it would set the Database Recovery option to "Simple". Now
after shifting to SQL Server 2005, this option is being set to "Full" by
default for every new database. Can someone tell me where is this property
inherited from for every new database and can be changed so that each new
database may get default value of Recovery option to "Simple"
Thanks in advance
Usman
It is inherited from the recovery mode of you "model" database.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Usman" <usman@.advcomm.net> wrote in message news:u9mhHeJVGHA.5364@.tk2msftngp13.phx.gbl...
> Hi
> I've been using SQL Server 2000 for quite some time. Every new database I
> used to add, it would set the Database Recovery option to "Simple". Now
> after shifting to SQL Server 2005, this option is being set to "Full" by
> default for every new database. Can someone tell me where is this property
> inherited from for every new database and can be changed so that each new
> database may get default value of Recovery option to "Simple"
> Thanks in advance
> Usman
>

Database Recovery Model Default value

Hi
I've been using SQL Server 2000 for quite some time. Every new database I
used to add, it would set the Database Recovery option to "Simple". Now
after shifting to SQL Server 2005, this option is being set to "Full" by
default for every new database. Can someone tell me where is this property
inherited from for every new database and can be changed so that each new
database may get default value of Recovery option to "Simple"
Thanks in advance
UsmanIt is inherited from the recovery mode of you "model" database.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Usman" <usman@.advcomm.net> wrote in message news:u9mhHeJVGHA.5364@.tk2msftngp13.phx.gbl...[v
bcol=seagreen]
> Hi
> I've been using SQL Server 2000 for quite some time. Every new database I
> used to add, it would set the Database Recovery option to "Simple". Now
> after shifting to SQL Server 2005, this option is being set to "Full" by
> default for every new database. Can someone tell me where is this property
> inherited from for every new database and can be changed so that each new
> database may get default value of Recovery option to "Simple"
> Thanks in advance
> Usman
>[/vbcol]

Database Recovery Model Default value

Hi
I've been using SQL Server 2000 for quite some time. Every new database I
used to add, it would set the Database Recovery option to "Simple". Now
after shifting to SQL Server 2005, this option is being set to "Full" by
default for every new database. Can someone tell me where is this property
inherited from for every new database and can be changed so that each new
database may get default value of Recovery option to "Simple"
Thanks in advance
UsmanIt is inherited from the recovery mode of you "model" database.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Usman" <usman@.advcomm.net> wrote in message news:u9mhHeJVGHA.5364@.tk2msftngp13.phx.gbl...
> Hi
> I've been using SQL Server 2000 for quite some time. Every new database I
> used to add, it would set the Database Recovery option to "Simple". Now
> after shifting to SQL Server 2005, this option is being set to "Full" by
> default for every new database. Can someone tell me where is this property
> inherited from for every new database and can be changed so that each new
> database may get default value of Recovery option to "Simple"
> Thanks in advance
> Usman
>

Sunday, February 19, 2012

DataBase Query help

Here's my situation:

I've got a column in one table called PRODID, and each value in this column references 1 or more values, say OrderDates, and I was wondering whether it's possible to write a query that returns all the values in the PRODID along with the latest OrderDate of the relevant PRODID value into the following result set:

PRODID OrderDate
1 "Latest Date"
2 "Latest Date"

And so on. Latest Date refers to the DateTime shown under OrderDates.

All help appreciatedSELECT P.ProductID, MAX(O.OrderDate)
FROM Orders O
INNER JOIN Products P ON O.ProductID = P.ProductID
GROUP BY P.ProductID|||Thanks for that, but I was just wondering is there any way to modify that query so that if any values for ProdID do not have an orderDate, the result set also returns these ProdIds but with a null value for the OrderDate?|||Actually ignore my last post, I managed to modify it to suit my eact needs, thanks for showing me the code though

Database Query

Is it possible to return the column names from the database using a SQL query,
what i need to do is
SELECT * FROM FEATURES WHERE 'VALUE' = 'YES'

i have a table which has a list of features and if they are selected i store the value yes, otherwise no . i want to be able to display a list of the features from the tables which have the value yes ! is this possible?yes xcept you dont need quotes around the column name..


SELECT * FROM FEATURES WHERE VALUE = 'YES'

hth|||Cheers but I worded the problem badly, VALUE isnt the name of the column, their are a number of different columns, each with different names, and i only want to display the column name if the value is yes ! any idea's?|||you wound then need to use CASE statement...check BOL for xact syntax but its something like


...
CASE
WHEN
colname='yes' then colname
ELSE NULL

hth|||what is BOL?|||BOL = Books Online

It is SQL Server's documentation.