|
Hi
I am not clear with your question, do you want to get two maximum values from a column without using cursor?
Please go thro' the following SQL Script, I am not sure whether you are looking for this solution:
USE northwind<br />
<br />
DECLARE @MaxStock SMALLINT<br />
DECLARE @NextMaxStock SMALLINT<br />
<br />
SELECT <br />
@MaxStock = MAX(UnitsInStock) <br />
FROM <br />
PRODUCTS<br />
<br />
SELECT <br />
@MaxStock<br />
<br />
SELECT <br />
@NextMaxStock = MAX(UnitsInStock) <br />
FROM<br />
PRODUCTS <br />
WHERE <br />
UnitsInStock < @MaxStock<br />
<br />
SELECT <br />
@NextMaxStock<br />
<br />
SELECT <br />
@MaxStock + @NextMaxStock<br />
Hope this is clear.
Harini
|
|
|
|
|
You could try something like:
Select Sum(AttributeValue)<br />
From<br />
(<br />
Select top 2 AttributeValue<br />
From UserAttributes<br />
Order by AttributeValue desc<br />
)
Wout Louwers
|
|
|
|
|
This was exactly what I was trying to do. Thanks!
Broken Bokken
You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod
http://www.brokenbokken.com
|
|
|
|
|
I'm trying to retrieve an image from Sybase DB using VB.Net. The field (sImage) is of type
"image". I've tried with dataset and dataReader, but no luck so far.
Here is what I have done:
This code works fine for SQL Server database.
Example:
Dim strConn As String
Dim strQuery As String
Dim objConn As OleDbConnection
Dim objDs As New DataSet
Dim intId As Integer
Dim objDa As OleDbDataAdapter
intId = Request.QueryString("uniqueId").ToString()
strQuery = "Select SImage From IMAGE Where ImageId= " & intId
strConn = ConfigurationManager.AppSettings.Get("ConStr")
objConn = New OleDbConnection(strConn)
objDa = New OleDbDataAdapter(strQuery, objConn)
objDa.Fill(objDs)
If Not IsNothing(objDs) AndAlso objDs.Tables.Count > 0 Then
Response.BinaryWrite(objDs.Tables(0).Rows(0)("SImage"))
End If
objDa.Dispose()
The code gave me this error:
"Invalid cursor position"
I'm using The Sybase DB version 9 .0.1
I'm stuck here so please help me!
Venu
|
|
|
|
|
Hi
I installed "QAnywhere patch to a Version 9.0.2" and "SQL Anywhere Bug Fix Readme for Version 9.0.2, build 3320". Now my code works fine.
Venu
|
|
|
|
|
Hi all,
I have a dataset containing a few tables. Now i want to create a new MS Access database, and populate it with the tables of this dataset. How do i do it programatically?
Can someone provide me with code snippets of how to create a new MSAccess database with a dataset in C#?
Would really appreciate an early response. Its quite urgent
Please Help...
Thanks
Shreyas
|
|
|
|
|
|
I have tried that too..and given up.. Does anyone know how to do it????
Shreyas
|
|
|
|
|
Sorry.. found something.. Thanks a lot
|
|
|
|
|
I am glad
I Love T-SQL
|
|
|
|
|
Can anyone Help
I have Create the weekday table in sql server 2005.
Total three field is there in weekday table.
1)DayOfTheWeek
2)OfficeOpenHours
3)OfficeCloseHours
I have enter the value Sunday to Friday in DayOfTheWeek field.
I have set the primarykey in DayOfTheWeek field.
When i set the primary key its automatically set the value in ascending order format.
Before Set the Primary key in DayOfTheWeek field value
*******************************************************
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
After Set the Primary key in DayOfTheWeek field value
*****************************************************
Friday
Monday
Saturday
Sunday
Thursday
Tuesday
Wednesday
How to enter the sunady to Saturday value format with primarykey.
USE [checkweekday]
GO
/****** Object: Table [dbo].[weekday] Script Date: 04/28/2008 17:00:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[weekday](
[DayOfTheWeek] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OfficeOpenHours] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OfficeCloseHours] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [PK_holiday] PRIMARY KEY CLUSTERED
(
[DayOfTheWeek] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
|
|
|
|
|
An easy solution would be to add a sequence column and order by that.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi everybody.
I have got some huge *.dbf files that a DOS based application updates them every minute
and also I want to use those files in a windows based application but there is a problem!
as I said my files are huge ( more than 5000000 records on each file ) and it takes a long time to read them with .NET ODBC driver. I think that if I link the files to SQLServer ( linked server ) and split them to small and usefull tables maybe it solves the problem. if it is possible say how can link the *.dbf files to SQL server ( Conection string, and other configuration ).Or are there any other solution? help me please!?
|
|
|
|
|
Hi,
I have a table with username and Registration number. I need to get the Registration number for the distinct usernames from the table.Can it be done using the "DISTINCT" query.?
|
|
|
|
|
Maybe. Why not try it and see?
Bob
Ashfield Consultants Ltd
modified on Monday, April 28, 2008 2:56 AM
|
|
|
|
|
I tried it , Since i can get only the Username , How to select the registration numbers from it? , Is there any other way to frame the query?
|
|
|
|
|
1. Post some samples from your table
2. Post your query
Then I will be able to help. If you have data like this:
Name Reg
M. Mouse 1
D Duck 2
then
SELECT DISTINCT Name, reg
from table
will do it.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
My Table entries are
Name Reg
M. Mouse 1
D Duck 2
L Lion 3
D Duck 4
M. Mouse 5
SELECT DISTINCT Name, reg
from table
This query gives the distinct combinations of name and reg not the distinct values for name . Since the combinations are unique all the entries will be returned .I need to get only Reg No's: 1,2,3
Any idea on How to frame the query for it?
|
|
|
|
|
here it is:
select distinct [name],<br />
(select top 1 a1.reg from myTable as a1 where a1.name = myTable.name order by a1.reg asc)<br />
from myTable
I Love T-SQL
modified on Monday, April 28, 2008 3:57 AM
|
|
|
|
|
Thanks for ur help,
Its working fine now..
|
|
|
|
|
You are welcome.
I Love T-SQL
|
|
|
|
|
If you are using SQL Server 2005, you should avoid subselects, because their performance is poor.
I'd rather use:
SELECT
NAME
, MIN(REG)
FROM dbo.MYTABLE
GROUP BY
NAME
|
|
|
|
|
thanks but your reply is not for me.
I Love T-SQL
|
|
|
|
|
When I run this code I get this error message "Syntax error in INSERT INTO statement". Can anyone explain why my command is a syntax error? Thanks.
rsGuest.Open("Guest", ADOConnection, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)<br />
Dim command As String<br />
<br />
<br />
command = "INSERT INTO Guest(Guest ID) VALUES('1111')"<br />
ADOConnection.Execute(command, rsGuest)
|
|
|
|
|
There are two possible reasons I can see.
Firstly, your syntax is wrong:
command = "INSERT INTO Guest(Guest ID) VALUES('1111')"<br />
Should be
command = "INSERT INTO Guest<big>[</big>Guest ID<big>]</big> VALUES('1111')"
Also, is [Guest ID] an identity (autonumber) column?
Bob
Ashfield Consultants Ltd
|
|
|
|