Retrieving Maximum Of Two Column Values

Oct 8, 2007



Hi,

I have a table with 3 colums and col1 and col2 are datetime columns as follows

ID Col1 Col2
----------------------------------------
1 D1 NULL
2 D2 D3
3 NULL D4

I want to retrive the ID along with the latest date from either of remaining columns.

Can any one let me know the query please??
~Mohan

View 6 Replies


ADVERTISEMENT

Retrieving Selected Gridview Column Values For SQLDatasource Asp:controlparameters

Jun 12, 2006

Not sure if this is the correct forum, but I 'm having problems retrieving a sqldatasource's asp:control parameter values from a selected row (during edit) in a gridview to update a record thru a stored procedure.  The stored procedure is pretty intense, so I'd like to keep it in SQL if possible instead of creating the generic "update table set ..." that I see in most examples.  It seems as if I can't get the propertyname right or something because it keeps giving me a "Procedure or function XX has too many arguments specified error".  Maybe the DataKeyNames is not right??  I've tried just passing one parameter (ProductID-same as DataKeyNames) using "SelectedValue" as propertyname and still get the same.  It's got to be something very simple, but I'm at a loss.  All parameters are spelled the same in the sp (with an added "@" at start) as in the asp:controlparameters.  Here's the gridview (asp.net 2.0 connecting to SQL Server 2005):
<asp:GridView ID="gvLoadEditProductPrices" runat="server" AutoGenerateColumns="False" AllowSorting="True" DataSourceID="SqlDataSource1" DataKeyNames="ProductID">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" HeaderStyle-BackColor="white" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" ReadOnly="True" />
<asp:BoundField DataField="ProductCat" HeaderText="ProductCat" SortExpression="ProductCat" ReadOnly="True" />
<asp:BoundField DataField="VarRate" HeaderText="VarRate" SortExpression="VarRate" />
<asp:BoundField DataField="loadid" HeaderText="loadid" InsertVisible="False" ReadOnly="True"
SortExpression="loadid" />
<asp:BoundField DataField="loadamount" HeaderText="loadamount" SortExpression="loadamount" ReadOnly="True" />
<asp:BoundField DataField="ProductCol" HeaderText="ProductCol" SortExpression="ProductCol" ReadOnly="True" />
<asp:BoundField DataField="PageID" HeaderText="PageID" SortExpression="PageID" ReadOnly="True" />
</Columns>
</asp:GridView>
and the sqldatasource's info:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MARSProductEditor %>" ProviderName="System.Data.SqlClient" SelectCommand="spGetLoadEditProductPrices" SelectCommandType="StoredProcedure" UpdateCommand="spUpdateProductPrices" UpdateCommandType="StoredProcedure" >
<UpdateParameters>
<asp:ControlParameter Name="ProductID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("ProductID")></asp:ControlParameter>
<asp:ControlParameter Name="LoadID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("LoadID")></asp:ControlParameter>
<asp:ControlParameter Name="PageID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("PageID")></asp:ControlParameter>
<asp:ControlParameter Name="ProductCol" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("ProductCol")></asp:ControlParameter>
<asp:ControlParameter Name="NewRate" Type="Double" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("NewRate")></asp:ControlParameter>
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="ddlEstLoadsPerAcre" Name="LoadID" PropertyName="SelectedValue"
Type="Int32" />
<asp:ControlParameter ControlID="txtEditType" Name="PageName" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
 
TIA,
John

View 1 Replies View Related

Minimum/Maximum Of Two Values

Dec 6, 2004

Hallo Cracks,

what I try is a little bit heavy, maybe, but I only miss the minimum/maximum fuction - or I didn´t found it; not here in the Forum and also not in the onlinehelp of the SQL Server.

What I try to do:

I have 2 columns in my table; a start- and an end-date. For this period of time between end and start i have to calculate the days for the years. Here my thoughts (for the current year):

Is the startdate <= 31.12.2004 and the enddate >= 1.1.2004 i have to calculate die datediff between max(1.1.2004/startdate) and min(31.12.2004/enddate)

like this sqlstatement:

SELECT CASE WHEN dbo.Phases.phasenstart <= CAST(CAST(YEAR(GETDATE()) AS
varchar) + '-31-12' AS smalldatetime) AND dbo.Phases.phasenabschlussist >=
CAST(CAST(YEAR(GETDATE()) AS varchar) + '-01-01' AS smalldatetime)
THEN 365 ELSE 0 END AS Expr2,
FROM dbo.Phases
WHERE (phasenstart IS NOT NULL) AND (phasenabschlussist IS NOT NULL)

instead of 365 there must be the above calculation. Is start=3.1.2003 and end=30.1.2004 I expect as result only the 30 days in 2004.

thanks in advance and kind regards :-)
Cappu

View 2 Replies View Related

Get Maximum From Each Datetime Values

Mar 5, 2008

hello all,

i have table - compmail in that i have compmailid, compmaildetail and compmaildate - columns

compmailid compmaildetail compmaildate
-------------------------------------------
94341 comp mailing list 2008-1-23 16:41:17.037
94445 comp mailing vital 2008-1-23 23:05:18.152
94592 comp mailing items 2008-1-24 10:48:08.077
108229 comp mailing sales 2008-1-27 15:13:37.207
108740 comp mailing usages 2008-1-27 16:44:17.517
108261 comp mailing stats 2008-1-27 14:42:55.780

so i want maxcompmailid for each date
so output will be like:

compmailid compmaildetail compmaildate
-------------------------------------------
94445 comp mailing vital 2008-1-23 23:05:18.152
94592 comp mailing items 2008-1-24 10:48:08.077
108740 comp mailing usages 2008-1-27 16:44:17.517

if i m doing:

select max(compmailid),compmaildetail,max(compmaildate) from compmail
group by compmaildetail

not giving me correct results which i want

can anyone have idea?

View 4 Replies View Related

Reporting Services :: Count Values In A Column Based Upon Distinct Values In Another Column In SharePoint List

Sep 7, 2015

We have SharePoint list which has, say, two columns. Column A and Column B.

Column A can have three values - red, blue & green.

Column B can have four values - pen, marker, pencil & highlighter.

A typical view of list can be:

Column A - Column B
red  - pen
red - pencil
red - highlighter
blue - marker
blue - pencil
green - pen
green - highlighter
red  - pen
blue - pencil
blue - highlighter
blue - pencil

We are looking to create a report from SharePoint List using SSRS which has following view:

                    red     blue   green
    pen            2       0      1
    marker       0       1      0
    pencil          1       3      0
    highlighter  1       1      1 

We tried Sum but not able to display in single row.

View 2 Replies View Related

Get Minimum And Maximum Values From Field?

Sep 16, 2012

I am trying to get the minimum and maximum values from a field in SQL Server 2008 Express, but I cannot even get started because I keep getting this error that I cannot figure out.

View 6 Replies View Related

Sum And Select Maximum Values From Table

Feb 13, 2014

I am using this below query to sum and select maximum values from table. I have converted the cost column here and how can I possibly sum the cost column?

select ID, MAX(Dates) Dates,'$ ' + replace(convert(varchar(100),
convert(money, Cost), 1), '.00', '') Cost, MAX(Funded) Funded from Application group by ID, Dates, Cost, Funded

View 4 Replies View Related

Integration Services :: SSIS Package - Replacing Null Values In One Column With Values From Another Column

Sep 3, 2015

I have an SSIS package that imports data from an Excel file, replaces any value in Excel that reads "NULL" to "", then writes the data to a couple of databases.

What I have discovered today, is I have two columns of dates, an admit date and discharge date column, and what I need to do is anywhere I have a null value in the discharge date column, I have to replace it with the value in the admit date column. 

I have searched around online and tried a few things using the Replace funtion in Derived columns but no dice so far. 

View 3 Replies View Related

Retrieving Values From Dynamic SQL

Nov 1, 2004

Anyone know if it's possible to retrieve a parameterized value from dynamically executed SQL???

Code Example

Declare @table varchar(25)
Declare @somevalue varchar(3)
Set @table = 'sometable'
Set @somevalue = 'somevalue'

Declare @sqlBuild varchar(2000)

Set @sqlBuild = 'DECLARE @return varchar(3); ' +
' SELECT @return = COUNT(COLUMNAME) ' +
' FROM ' + @table +
' WHERE ' +
' value = ' + @somevalue
exec (@sqlBuild)


i want to be able to extract the value of @return for later use. this procdure works fine but I need to grab that value somehow.

Any suggestions?

View 3 Replies View Related

Add Symbol To Column Values And Convert Column Values To Western Number System

Feb 12, 2014

I want to add $ symbol to column values and convert the column values to western number system

Column values
Dollar
4255
25454
467834

Expected Output:
$ 4,255
$ 25,454
$ 467,834

My Query:
select ID, MAX(Date) Date, SUM(Cost) Dollars, MAX(Funded) Funding from Application

COST is the int datatype and needs to be changed.

View 2 Replies View Related

TSQL - Generating New Column With The Maximum Value Of Other Column

Dec 2, 2007

Hi guys,
In the query below, I need to insert a new Column that shows the last Document date.
In example,
Document Date Last Date
2006/01/15 2007/11/30
2007/03/25 2007/11/30
2007/11/30 2007/11/30
I need to show the last (max) date for each row.
Thanks in advance for any help,
Aldo.




Code Block
SELECT
Stock.VALUEDATE AS 'Document Date'

FROM
Stock As Stock
INNER JOIN ACCOUNTS AS Accounts
LEFT OUTER JOIN ACCSORTNAMES AS AccSortNames ON Accounts.SORTGROUP = AccSortNames.ACCSORTCODE
LEFT OUTER JOIN EXTRANOTES AS ExtraNotes01 ON Accounts.ACCOUNTKEY = ExtraNotes01.KEF AND ExtraNotes01.NOTEID IN ('17')
LEFT OUTER JOIN EXTRANOTES AS ExtraNotes02 ON Accounts.ACCOUNTKEY = ExtraNotes02.KEF AND ExtraNotes02.NOTEID IN ('18') ON Stock.ACCOUNTKEY = Accounts.ACCOUNTKEY
INNER JOIN DOCUMENTSDEF AS DocumentsDef ON Stock.DOCUMENTID = DocumentsDef.DOCUMENTID

WHERE
Accounts.SORTGROUP Between '0' AND '379' AND
Accounts.SORTGROUP Not Between '100' AND '150'
AND Stock.DOCUMENTID In ('1', '4', '5', '11', '78', '95')
AND Stock.STATUS Not In ('0', '2')
AND Accounts.SORTGROUP Between '0' AND '379'
AND Accounts.ACCOUNTKEY Like '313%'

View 10 Replies View Related

T-SQL (SS2K8) :: Getting Minimum And Maximum Values In A Large Table

May 23, 2014

Table definition:

Create table code (
id identity(1,1)
code
parentcode
internalreference)

There are other columns but I have omitted them for clarity.

The clustered index is on the ID.

There are indexes on the code, parentcode and internalreference columns.

The problem is the table stores a parentcode with an internalreference and around 2000 codes which are children of the parentcode. I realise the table is very badly designed, but the company love orms!!

Example:
ID| Code| ParentCode| InternalReference|
1 | M111| NULL | 1|
2 | AAA | M111 | 2|
3 | .... | .... | ....|
4 | AAB | M111 | 2000|
5 | M222 | NULL | 2001|
6 | ZZZ | M222 | 2002|
7 | .... | .... | .... |
8 | ZZA | M222 | 4000|

The table currently holds around 300 millions rows.

The application does the following two queries to find the first internalreference of a code and the last internal refernce of a code:

--Find first internalrefernce
SELECT TOP 1 ID, InternalReference
FROM code
WHERE ParentCode = 'M222'
Order By InternalReference

-- Find last ineternalreference
SELECT TOP 1 ID, InternalReference
FROM code
WHERE ParentCode = 'M222'
Order By InternalReference DESC

These queries are running for a very long time, only because of the sort. If I run the query without the sort, then they return the results instantly, but obviously this doesn't find the first and last internalreference for a parentCode.

I realize the best way to fix this is to redesign the table, but I cannot do that at this time.

Is there a better way to do this so that two queries which individually run very slowly, can be combined into one that is more efficient?

View 7 Replies View Related

SQL Server 2012 :: Retrieving Null Values

Sep 10, 2015

Question in review today is Creating a Report showing the FName, LName of all Employees not Specified in a region; I would assume "No Value to be Null" Correct?

Or is there another way for me to do this?

This is what I have so far...What am I missing that this is not showing me results?

Select Firstname, Lastname, Region
From Employees
WHERE Region LIKE 'null%';

View 3 Replies View Related

Retrieving Multiple Values Using Non-joined Files

Feb 25, 2008

Hi - I'm new to SSRS/SQL and have a situation I can't figure out. I've tried a number of things, but I'm not sure the best way to return a calculated column based on the structure of my tables.

I have a primary Detail table that tracks product testing results. The Detail records need to be calculated against a "Year" table that contains a set of values by year. This table contains a single record for each year. There isn't a direct key that joins these two tables.

The Detail table looks like:
Record ID: 9999
PO Number: 12345
Date: 12/1/2007
Test Result: 1.52

The Year table looks like:
Record ID: 1
Start Date: 10/6/2007
End Date: 6/14/2008
LowVal1: 1.0
HighVal1: 1.49
Incentive1: .05
LowVal2: 1.50
HighVal2: 1.59
Incentive2: .06
and so on...

The Detail records need to find the correct Year record based on the Detail date, find the correct value within the LowVal - HighVal range based on the Test Result value, and then multiply the Test Result by the correct Incentive value and return that value.


I was able to find the correct LowVal-HighVal range using an Expression in the report column. Now that I need multiple years, I can't figure out the best way to configure the query.

Any suggestions would be appreciated. Thanks in advance!

View 3 Replies View Related

Help Retrieving Values From 2 Similar Stored Procs

May 1, 2006

I created one stored proc, then copied it to create another similar stored proc with just some filtering changes in the second.  Now I want to obtain the results from both like this:

ProjFee   ProjGross  DailyRunRate  Var1  InHouse1  InHouse2  GrossGoal  Group Name  PostedAmount
---------------------------------------------------------------------------------------------------------------------------
Row# 1 from current stored proc
Row # 2 from called stored proc

so something like this I should get in the end for example when both results are combined:

ProjFee   ProjGross  DailyRunRate  Var1  InHouse1  InHouse2  GrossGoal  Group Name  PostedAmount
---------------------------------------------------------------------------------------------------------------------------
100000   33455        200                 300    345555      4455555    5666666     Arizona           56000
103400   22455        900                 700    777555      3333555    5444666     Illinois            660000


The first stored proc (CurrentMonthCollections_AZ) attempts to include the results of the second stored proc at the end (CurrentMonthCollections_IL) by calling it and inserting the fields into a temp table.

I was told by Angel to instead convert the second stored proc into a UDF...but having trouble with this.

What is the best approach to get the desired 2 rows back that I need in that fasion?

Here is the code for the 2 stored procs (very long so I will post as as links):

http://www.webfound.net/CurrentMonthCollections_AZ.txt
http://www.webfound.net/CurrentMonthCollections_IL.txt

Look at the end of CurrentMonthCollections_AZ.txt to see where I'm stuck in trying to select the results (ProjFee   ProjGross   DailyRunRate   Var1   InHouse1   InHouse2   GrossGoal   Var1   PostedAmount
) from both stored procs.

I don't think UNION is what I want because it will combine stuff...I just want 2 separated rows

View 7 Replies View Related

Retrieving Scalar Or Calculated Values From Stored Procedures With C#

Feb 4, 2007

I am trying to build an Sql page hit provider.  I am having trouble getting a count back from the database.  If I use ExecuteScalar it doesn't see any value in the returned R1C1.  If I use ExecuteNonQuery with a @ReturnValue, the return value parameter value is always zero.  Ideally I would like to use a dynamic stored proceudre if there are any suggestions for using them with C#.  My table has rvPathName, userName and a date.  I have the AddWebPageHit method working so I know data connection and sql support code in provider is working.  I think the problem is either in how I am writing the stored procedures or how I am trying to retrieve the data in C#.  Any help with this will be greatly appreciated.

View 5 Replies View Related

Retrieving Values From Stored Procedure Using FormView && SqlDataSource

Mar 3, 2008

Please excuse me if this question has been asked before; I couldn’t find it.  Perhaps someone could point me to the solution.
A few years ago I wrote an order-entry application in classic ASP that I am now re-writing in ASP.NET 2.0.  I am having very good success however I can’t figure out how to retrieve data from a stored procedure.
I am using the FormView & SqlDataSource controls with a stored procedure to insert items into an order.  Every time an item is inserted into the order the stored procedure does all kinds of business logic to figure out if the order qualifies for pricing promotions, free shipping, etc.  If something happens that the user needs to know about the stored procedure returns a message with this line (last line in the SP)
 SELECT @MessageCode AS MessageCode, @MessageText AS MessageText 
I need to retrieve both the @MessageCode and the @MessageText values in my application.  In classic ASP I retrieved these values by executing the SP with a MyRecordset.Open() and accessing them as normal fields in the recordset.
In ASP.NET I have specified the SP as the InsertCommand for the SqlDataSource control.  I have supplied all the parameters required by my SP and told the SqlDataSource that the insert command is a “StoredProcedure?.  Everything actuly works just fine.  The items are added to the order and the business logic in the SP works fine.  I just have no way of telling the user that something important has happened.
Does anyone know how I can pickup these values so that I can show them to my users?  Bassicly if @MessageCode <> 0 I want to show @MessageText on the screen.

View 10 Replies View Related

Retrieving Default Values For Parameters In A Stored Procedure.

Jul 23, 2005

I'm generating a list of parameters needed by stored procedures, and
I'd like to know which ones have default values assigned to them.
To retrieve the parameter information I use:


sp_sproc_columns @Procedure_Name='InsertUser''


However, the column that is supposed to give the default value,
'COLUMN_DEF' always returns as NULL, even when that column has a
default value assigned to it.
i.e.
CREATE PROCEDURE InsertUser@UserID INT = 10,.....


And then if I do a sp_sproc_columns @Procedure_Name='InsertUser'', the COLUMN_DEF value for the @UserID column is still NULL.

Does anyone know what I'm doing wrong and how I can retrieve the default value?

Thanks

View 1 Replies View Related

SQL Server 2012 :: Nested Query Retrieving Min And Max Values?

Jul 16, 2015

I have a nested query that retrieves a min value. I would like to know how do i retrieve the corresponding time with that.

my data looks like this

valuevaluetime
1212/31/14 14:51
12.42/19/15 23:30
[highlight=#ffff11]10.92/21/15 6:40[/highlight]
13.21/25/15 20:47

My min value is 10.9 and i need the date 02/21/15

my nested query is as follows

( select min(cast(f.valuestr as float))
from bvfindings f
where f.ObjectName = 'Hematocrit'
and f.sessionid = s.sessionid
and f.ValueTime > s.open_time)

the above returns me the 10.9

i modified the query

select min(cast(f.valuestr as float)),
f.valuetime
from bvfindings f
where f.ObjectName = 'Hb'

but i get all values then.

View 6 Replies View Related

Retrieving Values From A Subreport To Body Of Parent Report

Mar 7, 2007

Is it possible to retrieve the value of a subreport's field or control from the parent report? I'm doing some grouping in the subreport and need to retrieve the group by's data value from the subreport.

Also, is there a way to repeat the main page's body when subreport has a page break? ie you page break on some thing in the subreport and need the body and head of the parent report to repeat on subsequent pages.

Thanks,
Garick

View 3 Replies View Related

Retrieving Values From Print Statemens In Stored Proc In Sql Into Asp.net Page

Sep 3, 2007

 Hi allI hv made a stored procedure which printsvarious messages using Print statement(shown in bold)------------------------------------------------------------------------------ .....if (@current_date<@ed) and (@current_date>@sd)    begin    print 'Date Lies Between Boundary Limits'    select * from membership where uid=@uid    end    else    begin    if(@pipe=1)            begin                if(@plan_id=1)                begin                 print 'Monthly Plan Activated'                update membership set   start_date=@opt_sd,end_date=DateAdd(M,1,@opt_sd),status=@opt,pipeline=0,user_option='',plan_id=null,download_limit=20 where uid=@uid                select * from membership where uid=@uid                end                else                    begin                    print 'Weekly Plan Activated'                    update membership set start_date=@opt_sd,end_date=DateAdd(D,7,@opt_sd),status=@opt,pipeline=0,user_option='',plan_id=null,download_limit=10 where uid=@uid                    select * from membership where uid=@uid                    end            end    end --------------Now I want to retrieve the messages disp by these Print statements in my asp.net page where i m calling this stored proc.Pls suggest RegardsMunish 

View 2 Replies View Related

Retrieving Rows Of Database Values That Have Numbers Cloest To Our Input

Jan 11, 2008



Mean_A Std_Dev_A Mean_B Std_Dev_B Mean_C Std_Dev_C X_Co Y_Co Posn



71.7
9.36
73.23
3.62
70.87
4.06
12
14
1

72.69
8.02
79.39
2.66
73.39
5.16
13
15
2

74.37
10.27
77.33
4.10
79.33
3.44
14
16
3














The Above is my database, I need help in retrieving the X_Co and the Y_Co using values of rcv_A, rcv_B and rcv_C to compare with the Mean_A, Mean_B, Mean_C. The values of rcv_A, rcv_B and rcv_C are instances of values that are not exact of the mean columns , and we want is to compare it against our database and retrieve the row that is the closest to the rcv_A, rcv_B and rcv_C.

Here is an example of what i need. Let's say my rcv_A = 71, rcv_B = 73 and rcv_C = 70.8, so the row with mean value closest would be row 1, followed by row 2, then row 3.

So the result i hope to retrieve is in order of the closest value and i only need the X_Co and Y_Co.
This is what i want

X_Co Y_Co
---------------------------
12 14
13 15
14 16

So anyone please can help me in querying for the above results? Thanks

View 5 Replies View Related

Maximum Characters Per Column

Mar 11, 2002

Is there a way to alter the default 256 value to some other value in a transac SQL script?
The value can be changed manually in the advanced tab of the current connection options. I need to be able to set and reset this value in a script and/or stored procedure.
Kind of urgent for an answer to this problem.
Thanks in advance.

View 1 Replies View Related

Maximum Chars Per Column - 256

Sep 23, 1999

In a query Analyser, there is a provision to change the "Maximum characters per column 256 " to our size in advanced option.

It works ok.

We are using VisualInterdev for developing ASP's -- there
thro ADO - we are getting the rows from sql server 7.0 -- there data more than
256 characters are truncated.

How will i get the actual data ?.. where i can do the settings..?

help needed...

Wincy

View 2 Replies View Related

Maximum Row Length Of A Column

Nov 8, 1999

Friends,

I was trying to find out the maximum length of a row in a column.I was using SQL65.I will appreciate if any one can give me the query to find this.

Thanks in advance

View 3 Replies View Related

How To Get Maximum Count Of A Column In A Table.

Dec 6, 2007

i have a table with productID and OrderID. For ech product there are orders.
So for each productID there are lot Of OrderID's are present.
My data like

ProductID OrderID

1 12012
1 12447
1 12478
2 24154
2 21457 etc.......

so, i need to get the maximum count for a product.

i can do by using Temporary tables. but i need without using temporary tables.

please help me out.

thanks
-Praveen.

View 12 Replies View Related

Retrieving Column Name And Value For Each Row Using GetSchemaTable

Jun 11, 2007

I know I can iterate through the schema table using the following.



Can I grab the actual value of each field while looping through the rows and columns?



schemaTable = reader.GetSchemaTable();

foreach (DataRow myDataRow in schemaTable.Rows)

{


foreach (DataColumn myDataColumn in schemaTable.Columns)

{




Console.WriteLine(myDataColumn + "= " + myDataRow[myDataColumn.ColumnName].ToString() );
}

}





An example is if one of the columns in the schema is called Firstname I would like to return:



Row 1

column name = Firstname

value= Bob

column name = Lastname

value= Smith



Row 2

column name = Firstname

value= Greg

column name = Lastname

value= Jones

View 3 Replies View Related

Overflow Problem On Decimal(38,14) Column With SQL2005 SP2 With Min Value Of 0.1 And Maximum Of 3.0

Apr 18, 2007

On table TABLENAME, I have increased the size of column C to decimal(38, 14); maximum size and an excessive amount of precision.
If I do a 
SELECT MAX(CONVERT(DECIMAL(7,2), A) / B) FROM TABLENAME
SELECT MIN(CONVERT(DECIMAL(7,2), A) / B) FROM TABLENAME
I get 3.0000000000000 for the MAX and 0.1000000000000 for the MIN value, yet if I update
UPDATE TABLENAME SET C = CONVERT(DECIMAL(7,2), A) / B WHERE B <> 0
Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting numeric to data type numeric.
The statement has been terminated.
Obviously I have obscured the column names and table name, but I am puzzled as to why values in the range 0.1 to 3.0 should give an overflow error.
I am using SQL2005 SP2

View 7 Replies View Related

Retrieving The BigInt Value From The Identity Column After Inserting

Jul 26, 2007

I have a database that has a tble with a field that autoincrements as a primary key. meanig that the field type is BigInteger and it is set up as my Identity Column. Now when I insert a new record that field gets updated automaticly.
How can I get this value in the same operation as my insert? meaning, in 1 sub, I insert a new record but then need to retieve the Identity Value. All in the same procedure. 
Waht is the way to achive this please?
Marc

View 2 Replies View Related

Retrieving Variant Column Datatype Using SQLColAttrubute

Jan 11, 2008

Hi,
When i try to retirve the datatype of a variant column using SQLColAttribute, the datatype comes back as SQL_BINARY(-2) instead of a CHAR based type. To reproduce the problem, add extended property 'MS_Description' to either a column or a table. Assign a text value to the property.


Execute the following query and verify. SELECT value FROM sys.extended_properties WHERE name = 'MS_Description'

I'm using SQL Server 2005 sp 2 with Visual Studio 2005.

Here is the code i use -




Code Block
SQLHENV m_SQLEnvironment;
SQLHDBC m_SQLConnection;
SQLHSTMT m_SQLStatement;
SQLRETURN iReturn;
CString sConnectionString = _T("DRIVER={SQL Native Client};SERVER=YourServer;DATABASE=YourDatabase;Trusted_Connection=yes;");

CString sQuery = _T("SELECT value FROM sys.extended_properties WHERE name = 'MS_Description'") ;

iReturn = SQLAllocHandle( SQL_HANDLE_ENV,SQL_NULL_HANDLE,&m_SQLEnvironment);
iReturn = SQLSetEnvAttr(m_SQLEnvironment,SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3,0);
iReturn = SQLAllocHandle(SQL_HANDLE_DBC,m_SQLEnvironment,&m_SQLConnection);
iReturn = SQLAllocHandle(SQL_HANDLE_STMT, m_SQLConnection, &m_SQLStatement );
SQLCHAR szwOutputConnectionString[800];
SQLSMALLINT nOutputStringLength = 0;
SQLUSMALLINT nDriverCompletion = SQL_DRIVER_NOPROMPT;
iReturn = SQLDriverConnect( m_SQLConnection, m_hWnd, (SQLCHAR*)(LPCSTR)sConnectionString, SQL_NTS, szwOutputConnectionString, 800, &nOutputStringLength, nDriverCompletion );

iReturn = SQLAllocHandle( SQL_HANDLE_STMT,m_SQLConnection,&m_SQLStatement);
iReturn = SQLPrepare( m_SQLStatement, (SQLCHAR*)(LPCSTR)sQuery , SQL_NTS );
iReturn = SQLExecute( m_SQLStatement );
iReturn = SQLFetch( m_SQLStatement );
SQLINTEGER nType = 0;
SQLSMALLINT nDummyInt = 0;

//get the datatype of the variant
iReturn = SQLColAttribute( m_SQLStatement, (SQLUSMALLINT) 1, SQL_CA_SS_VARIANT_TYPE, NULL, NULL, &nDummyInt, &nType );







After the execution of SQLColAttribute, nType value is assigned a value of -2 (SQL_BINARY) instead of a CHAR based type. What am i doing wrong? Any help is appreciated.



Regards,
Venkat

View 1 Replies View Related

Retrieving MSG Files From SQL Server Image Column

Dec 3, 2007

As part of a web site I allow users to store documents in SQL Server 2000 using an Image column on a table. After the file is saved the user can open the document through the browser. This works great for most file extensions such as ".XLS" or ".DOC" but fails when attempting to open ".MSG" files (saved outlook messages). XLS documents will open in Excel and DOC documents open in Word, but MSG documents open in Notepad and display what appears to be binary data. I'm trying to figure out if this is a SQL Server issue or some sort of ASP/ASP.NET webserver issue.

If I attempt to open an MSG file stored directly on the web server, the file opens correctly using the "Microsoft Outlook View Control", but when attempting to open the same file saved in SQL Server, it attempts to open in notepad.

Any ideas?

View 2 Replies View Related

Transact SQL :: Error - Maximum Row Size Exceeds Allowed Maximum Of 8060 Bytes

Sep 12, 2015

I have some code I build 2 weeks ago which I’ve been running daily but it’s suddenly stopped working with the following error.

“The table "tbl_Intraday_Tmp" has been created, but its maximum row size exceeds the allowed maximum of 8060 bytes. INSERT or UPDATE to this table will fail if the resulting row exceeds the size limit” When I google this there seems to be a related to tables with vast numbers of columns.

My table tbl_Intraday_tmp is relatively small. It has 7 columns. 1 of varchar(5), 3 of decimal(9,3) and 2 of decimal(18,0). The bit I’m puzzled with is it was working and stopped.

I don’t recall changing anything but I wouldn’t rule that out. I ‘ve inspected the source files and I don’t believe they have changed either.

DECLARE              
@FileName varchar(50),
@Path varchar(50),
@SqlCmd varchar(1000)
= '',
@ASXCode varchar(5),
@Offset decimal(18,0),

[code]....

View 5 Replies View Related

Error - Maximum Row Size Exceed Allowed Maximum Of 8060 Bytes

Apr 20, 2012

I am using MS SQL server 2008, and i have a table with 350 columns and when i m trying to create one more column its giving error with below message -

Warning: The table XXX has been created, but its maximum row size exceeds the allowed maximum of 8060 bytes.

INSERT or UPDATE to this table will fail if the resulting row exceeds the size limit.

how can i resolve this?

View 14 Replies View Related







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