SQL Syntax Returning Wrong Records

Nov 23, 2007

Hi

I have a table called DiaryDate2 and a query called DiaryDateOver8 and want to have a sql query to return the records from the table that are not in the query based on two linked fields username and Diarydate1

The SQL I have written however returns all records

SelectCommand="SELECT  DiaryDate2.Username, DiaryDate2.DiaryDate1 FROM DiaryDate2

WHERE(DiaryDate2.Username = ?)AND NOT EXISTS (SELECT 1 from DiaryDateover8 where DiaryDateover8.Username=DiaryDate2.Username AND DiaryDateover8.DiaryDate1=DiaryDate2.DiaryDate1)ORDER BY DiaryDate2.DiaryDate1">

Please could someone help

Many thanks Colin

View 5 Replies


ADVERTISEMENT

Query Returning Multiple Wrong Values

Jan 16, 2013

I've got this sql statement that keeps returning the wrong data. (it's related to a previous post, but is different)

Code:
SELECT C.NAME, OL.PART_ID, SL.SHIPPED_QTY
FROM CUSTOMER C
INNER JOIN USERS U ON C.ID = U.ID
INNER JOIN ORDERS O ON C.ID = O.ID
INNER JOIN ORDER_LINE OL ON O.ID = OL.ORDER_ID

[Code] .....

The qry pulls like this: (wrong way)

HTML Code:
company partID Qty
Acme Inc ABC123 3
Acme Inc ABC123 4
Acme Inc ABC123 100
Acme Inc KLM444 3
Acme Inc KLM444 4
Acme Inc KLM444 100
Acme Inc QRP456 3
Acme Inc QRP456 4
Acme Inc QRP456 100

It should be:

HTML Code:
Co. part Qty
Acme Inc ABC123 3
Acme Inc KLM444 4
Acme Inc QRP456 100

The Qty field has duplicates. I've tried various ways, but I cannot make this work.

View 14 Replies View Related

SELECT * View Returning Wrong Column Data

Oct 16, 2007

SQL 2005 9.00.3402.00 (x64) As Above really when I select * OR select a single column from the view the wrong column data is returned. in SQL Management Studio when I expand the Columns of the view it reflects the old table structure not the new table structure. I can easily fix by compiling the view again but this would mean I would have to recompile all referencing views when I make a change to table structures. I've tried various DBCC Clean Buffers & drop cache with no effect. Is there a command to recompile all views & poss stored procs in a database. Any help or explanation would be appreciated GW

View 12 Replies View Related

SQL Server 2012 :: OUTPUT Clause Returning Wrong Row?

Nov 6, 2014

I'm looking at various methods for deleting duplicate rows. Among the alternatives, one works just fine but gives me results that make me go?.

Consider this script:

declare @t table (a int, b int, c int, d int, e int)
insert into @t (a, b, c, d, e) values
(1, 2, 3, 4, 5),
(3, 4, 2, 3, 4),
(1, 2, 3, 4, 5)

select a,b,c,d,e, rn = row_number() over (
partition by a,b,c,d,e

[Code] ....

The code works -- that is, the duplicate row is deleted. However the output clause returns:

abcdern
123451

So....why? Why does the output clause show that the row with rn=1 was deleted, when the where clause stipulates rn > 1?

View 9 Replies View Related

What Is Wrong With This Syntax?

May 21, 2006

Hello
I am trying to insert a hyperlink to display on my web site, via the database, for example:
http://www.tressleworks.ca/Modules/SQLGridSelectedView/LiveExamples/Example4Links/tabid/91/Default.aspx
Name of my table is:  Biz_Names
Cols:
ID_numberFNameLNameBusiness
I know that this works:
SELECT FName, LName, BusinessFROM BizNamesWHERE FName = 'John'
ORDER BY LName ASC
I want to add a hyperlink and I have since included extra columns:
ID_numberFNameLNameBusinessurltitleLink

I want to add the hyperlink from the url column and use the title from the title column to fill the Link column, I don't want to include the url and the title column on the site.
I only want to display Link data on the site, but so far my syntax is not working:
SELECT FName, LName, Business, '<a href='" + url '"> + Title +'</a>' as LinkFROM BizNamesWHERE FName = 'John'
And url like 'http:%'
ORDER BY LName ASC
What am I doing wrong?
Thanks
 
Regards
Lynn
 
 

View 2 Replies View Related

What's Wrong With This Having Syntax

Jul 28, 2007

It works in ASP-Access, but not on the Unix sql:

SELECT SUM(result.pt) as SumOfpt FROM result,team GROUP BY sref,tref,team.id HAVING sref=2 and team.id=tref;

it says - and only on the unix server:

SQLState: 4 Native Error Code: 1054 [TCX][MyODBC]Unknown column 'sref' in 'having clause'
/test/teamstandings.asp, line 20

View 11 Replies View Related

What Is Wrong W/ This Syntax?

May 24, 2007

"*** " + @[System::MachineName] + " - SSIS Package Error - [ " + @[System:ackageName] + " ] @ " + (DT_STR, @[System::ContainerStartTime]) + " ***"



Get this error:



TITLE: Expression Builder
------------------------------

Expression cannot be evaluated.

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%u00ae+Visual+Studio%u00ae+2005&ProdVer=8.0.50727.42&EvtSrc=Microsoft.DataTransformationServices.Controls.TaskUIFramework.TaskUIFrameworkSR&EvtID=FailToEvaluateExpression&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

Attempt to parse the expression ""*** " + @[System::MachineName] + " - SSIS Package Error - [ " + @[System:ackageName] + " ] @ " + (DT_STR, @[System::ContainerStartTime]) + " ***"" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

(Microsoft.DataTransformationServices.Controls)

------------------------------
BUTTONS:

OK
------------------------------



Thanks

View 3 Replies View Related

Whats Wrong With This Syntax..

Oct 2, 2007

CASE field_val
WHEN 'M5' THEN EXEC ( @query)
ELSE THEN print ''
END



I have a SP , and i state a query .. but i only
want this query to be executed based on the value
of field_val , otherwise i print a blank ..
but when i check the syntax (ms sql server 2000)
i get "invalid syntax near CASE ..

View 5 Replies View Related

Creating SQL View - Syntax Is Wrong

Apr 14, 2004

We are creating a view in SQL to format data to DTS to another database. Here is the section of the view which does not work -- eliminating this section from the query allows the view to be created:

CASE APTran.LineNbr
WHEN < '0' THEN 'O'
--Offsetting Document (or transaction line as we have (AP Liab. AP Cash Entry).
WHEN > '0' THEN 'D'
--Regular Document (or transaction line as we have (This is either a Debit or a Credit line not AP Liab. AP Cash Entry).
ELSE 'E'
END AS JED_DIST_OR_OFF,


I am attaching the whole query stmt here.

Thanks very much for all assistance.

View 6 Replies View Related

Syntax Error, Whats Wrong??

Mar 21, 2007

Hi heres my script, why does it not work?

CREATE PROC [dbo].[sp_append_CemexSQLDB_to_EQuIS5_V2]
@DBINnvarchar(50),
@DBOUTnvarchar(50)

AS

DECLARE @SQLStrVarchar(1000)

/* Start Transaction, incase of error */
BEGIN TRAN

/* Appending Ref tables */
SET @SQLStr = 'INSERT INTO ' + QUOTENAME(@DBOUT) '.dbo.rt_action_level_type'
SET @SQLStr = 'SELECT *'
SET @SQLStr = 'FROM ' + QUOTENAME(@DBIN) '.dbo.rt_action_level_type;' + ' OPTION (KEEP PLAN)'
EXEC (@SQLStr)
IF @@ERROR <> 0 GOTO ERRORHANDLER
COMMIT TRAN

RETURN 0

ERRORHANDLER:
PRINT "Unexpected Error Ocurred!"
ROLLBACK TRAN

RETURN 1
GO

The error is 'Server: Msg 170, Level 15, State 1, Procedure sp_append_SQLtables_to_NewDB_V2, Line 13
Line 13: Incorrect syntax near '.dbo.rt_action_level_type'.'


can anybody help

View 5 Replies View Related

Wrong Syntax In Where Smth In Case ?

Jul 23, 2005

Hello all,I belive, my problem is probably very easy to solve, but still, Icannot find solution:declare @iintdeclare @zintcreate table bubusilala ([bubu] [int] NOT NULL ,[gogo] [int] NOT NULL ,[lala] [varchar] (3) NOT NULL )insert into bubusilala (bubu,gogo,lala) values (1,2,'ala')insert into bubusilala (bubu,gogo,lala) values (10,20,'aca')insert into bubusilala (bubu,gogo,lala) values (100,200,'bbb')insert into bubusilala (bubu,gogo,lala) values (11,21,'ccc')insert into bubusilala (bubu,gogo,lala) values (12,22,'abc')insert into bubusilala (bubu,gogo,lala) values (13,23,'cbd')set @i = 10set @z = 2select * from bubusilalawhere bubu in (case when @i > @z then (1,2)when @i < @z then (10,13) end)and gogo like '%a%'I get error, that statement is wrong in case near ','.I supose, it is not possible, to get from case a group of values.But why then, this works:select * from bubusilalawhere bubu in (case when @i > @z then (1)when @i < @z then (select gogo from bubusilala) end)and gogo like '%a%'This data are totaly simplified.agrh ... any ideas??Thank You in advance,Mateusz

View 3 Replies View Related

C# Ado.net MSDE: Wrong Syntax Near The User Keyword

Apr 11, 2004

************* Edited by moderator Adec ***************
Inserted missing < code></ code> tags. Always include such
tags when including code in your postings. Many readers
disregard postings without the code tags.
**************************************************

Hello,

I have a big problem with some piece of code. I am new to C# and ado.net.
My MSDE 2000 is set up and running. But the following code produces the error
(translated from german) like "wrong syntax near the user keyword"

The connection to the database works fine. But trying to create a table or to drop
a table alwas leads to the error. Whats wrong with it?

try
{
SqlConnection myConnection = new SqlConnection( "server=(local);" +
"Trusted_Connection=yes;" +
"database=ergofun; " +
"connection timeout=10");
SqlCommand sqlCommand = new SqlCommand();

sqlCommand.Connection = myConnection;
sqlCommand.CommandText = "CREATE TABLE user ( userid INT," +
"nickname CHAR(20),"+
"password CHAR(20),"+
"birthday DATETIME,"+
"weight INT,"+
"size INT,"+
"puls INT,"+
"name CHAR(20),"+
"surname CHAR(20))";

sqlCommand.Connection.Open();
sqlCommand.ExecuteNonQuery();
sqlCommand.Connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

View 1 Replies View Related

Table Scalar Function Syntax. . How Wrong And How Far Am I?

Aug 3, 2006

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE FUNCTION DetailedView

AS

BEGIN

Declare @fieldname varchar(10)

Declare @stmt varchar(4000)

Declare Fields Cursor For Select Amounttype From Amounttypes

Set @stmt = 'Select pono, myid, billtype'

Open Fields

Fetch Next From Fields Into @fieldname

While @@Fetch_Status = 0 Begin

Set @stmt = @stmt + ', sum(amountfc * Case When amounttype = ''' + @fieldname + ''' Then 1 Else 0 End) As ' + @fieldname

Fetch Next From Fields Into @fieldname

End

Close Fields

Deallocate Fields

Set @stmt = @stmt + ' From multiplebillsviewall Group By pono, myId,billtype '

return Exec(@stmt)

END

View 3 Replies View Related

Syntax For Returning And Accessing Multiple Result Sets In MSSQL 2k

Dec 29, 2006

Seasons greetings to everyone,A simple question. Could someone show me the syntax to produce multiple (2 or 3) result sets in a stored proc and how you access those sets from a c# program (ASP.NET)..Couldn't find a reference on Google, maybe I was asking the wrong question! Thanks for any help regardsDavej 

View 3 Replies View Related

Returning Middle Records

Dec 7, 2006

I'm writing a page that will return data from my database to the user based on their search paramaters, over several pages with 20 matching records showing per page, and a next button on the bottom. Similar to the format of any search engine.
However, I'd like to write this into the query, and I'm not sure how I would go about doing so. For example:
 "SELECT TOP 20 to 40 * FROM Northwind"
 Hopefully this makes sense. Is there any way of doing this?
Thanks in advance,Russ

View 2 Replies View Related

Sqldatareader Not Returning Records

Feb 13, 2007

My query is as follows:Dim CurrentDate As DateCurrentDate = "09/02/2007" MyCommand = New SqlCommand("SELECT RegisterID FROM Registers WHERE RegisterDate = @RegisterDate AND IsMorningRegister = 1", MyConn)MyCommand.Parameters.Add("@RegisterDate", Data.SqlDbType.DateTime)MyCommand.Parameters("@RegisterDate").Value = CurrentDate My DB table is called RegisterDate and is of type DateTime. The record that should be matched is: Register ID: 13 RegisterDate: 09/02/2007 09:00:00IsMorningRegister: TrueIsAfternoonRegister: False But no records are returned. Any idea why?    

View 4 Replies View Related

Returning The Last Row From A Set Of Duplicate Records

Feb 27, 2002

Any information as to how to handle this?

Thanks.

View 1 Replies View Related

Returning A Specified Range Of Records

Jul 14, 2005

Hi,

I have a SQL question which I suspect is very easy to answer but can't seem to find one for.

I have a table which contains about 500 records. i would like to display these records on a web page, but paginated, showing only 20 records per page. I have in the past returned a recordset containing all the records and paginated programmatically in ASP. In this instance I would like to be able to pass an upper and lower bound into my stored proc and return only those records I want to display. So on page 4 I would want to display only records 61-80. I can pass in the upper and lower bound to the SP as parameters but is there some T-SQL i can use to return this range of records only.

So, the SP would for example accept the parameters

@Upperbound = 80
@Lowerbound = 61

and would return a recordset of 20 records being the 61st thru 80th record from the queried table.

Thanks for the help
Guy

PS. I asked someone at work and they suggested using OFFSET and LIMIT. It seems to me as if these are only available in PostgreSQL or MySQL and not T-SQL. I guess I am looking for an equivalent I can use with SQL Server.

View 4 Replies View Related

Proc Returning All Records

Nov 17, 2006

Following Proc is returning all records.I have passed any value to parameters but no luck.


CREATE PROCEDURE GetAllUsers(
@persontype varchar(100)="",
@name varchar(100)="",
@adddatetime datetime="",
@activeaccount int =-1,
@country varchar (20)=""
)
AS
declare @cond varchar(1000) ;

if @persontype<>""
begin
set @cond= @cond+"and persontype="+@persontype
end
if @name<>""
begin
set @cond= @cond+"and (charindex("+@name+",x_firstname)>0 or charindex("+@name+",x_lastname)>0 or charindex("+@name+",x_email)>0) "
end
if @activeaccount<>-1
begin
set @cond= @cond+'and activeaccount='+@activeaccount
end
if @adddatetime<>""
begin
set @cond= @cond+'and adddatetime='+@adddatetime
end
if @country<>""
begin
set @cond= @cond+'and x_country='+@country
end
print @cond
exec( " select * from users where 1=1 "+@cond)
GO



zx

View 2 Replies View Related

Help With Returning A Certain # Of Records From A View.

Jul 20, 2005

I have a view that will return say 5000 records when I do a simpleselect query on that view like.select *from vw_test_viewHow can I set up my query to only return a certain # of records, saythe first 300?Here is what is going on, we have a large amount of data that returnsin a view and we need to work with all of it eventually, However wewant to do it in chunks. So my thoughts were as follows:1. To run a query to return X amount of the total data for us to workwith.2. Update these records with a flag in a table that the vw_test_viewfilters out.3. The next time I run the query to pull data from the view it willskip the records that I have already looked at (because of step 2) andpull the next X amount of records.Thanks in advance,Mike

View 3 Replies View Related

Returning Billable Records.

May 15, 2008

Hello -

I'm trying to write a select statement that will return only "billable" records.
A record is billable if:
- it is the only record for a Case (Case is an FKey ID column in my records table)
OR
- the last billable record for Case X has a DateTime > 24 hours before the record in question.

Getting records for the first condition is easy:

SELECT ID FROM Records r
LEFT OUTER JOIN Records r2 ON r2.[Case] = r.[Case]
WHERE r2.[Case] IS NULL

It's the second part I'm having trouble with.

UNION
SELECT ID FROM Records
JOIN ?
....
WHERE DATEDIFF(hh, r.DateTime, r2.DateTime) > 24 ??

I have to assume there can be any number of records for a case.

Thanks in advance!

View 10 Replies View Related

Returning 30% Random Records

Sep 27, 2007

HI,

If i have the following data




Code Block

Create Table #Request (
[requestid] int ,
[customername] Varchar(30) ,
[age] int ,
[sex] char(1) ,
[address] Varchar(30) ,
[status] int
);

Insert Into #request Values('2342','Jack','23','M','Texas','0');
Insert Into #request Values('223452','Tom','45','M','Ohio','1');
Insert Into #request Values('22353','Bobby','23','M','Austin','0');
Insert Into #request Values('22362','Guck','23','M','Austin','0');
Insert Into #request Values('22392','Luck','23','M','Austin','1');
Insert Into #request Values('22362','Buck','23','M','Austin','0');
Insert Into #request Values('2564392','Jim','23','M','Austin','1');
Insert Into #request Values('2342','Jasm','23','M','Austin','0');
Insert Into #request Values('2765492','Chuck','23','M','Austin','1');





How can i return 30% random requestid's from this table?

thanks.

View 9 Replies View Related

Returning ALL Records In A Query

Aug 18, 2006

I'm building a db to collect equip fault data in SQL 2005 and need to modify my query to be able to select/display "ALL" records. I'm currently using a sp to assign a shift to each record and then have a query to select all records by shift. I'd like to add an option to the query to be able to select ALL records, regardless of shift. I've included the sp & query I am currently using. Any help would be appreciated.

Thanks

ALTER PROCEDURE [dbo].[p_dtu_Store_Line_Fault_Data]
-- Add the parameters for the stored procedure here
@AssetID int,
@Timestamp datetime,
@FaultCode int,
@State int
AS
BEGIN
SET NOCOUNT ON;
IF @State = 3
BEGIN
INSERT LineFaultData (FaultCode, AssetID, StartTime, Duration, Shift)
VALUES (@FaultCode, @AssetID, @Timestamp, 0,
CASE WHEN DATEPART(hh,@Timestamp) BETWEEN 7 AND 14 THEN 'DAYS'
WHEN DATEPART(hh,@Timestamp) BETWEEN 15 AND 22 THEN 'AFTERNOONS'
ELSE 'NIGHTS'
END)
END

IF @State <> 3
BEGIN
DECLARE @Count int
SET @Count = (SELECT Count(*) FROM LineFaultData WHERE AssetID = @AssetID AND Duration = 0)
IF @Count <> 0
BEGIN
DECLARE @StartTime datetime
SET @StartTime = (SELECT Top 1 StartTime FROM LineFaultData WHERE AssetID = @AssetID and Duration = 0)
UPDATE LineFaultData
SET Duration = DateDiff(s,@StartTime, @Timestamp)
WHERE AssetID = @AssetID and Duration = 0 and StartTime = @StartTime

END
END

END




SELECT TOP (1000) dbo.LineFaultDescription.Station, dbo.LineFaultData.StartTime, dbo.LineFaultData.Duration, dbo.LineFaultDescription.FaultDescription,
dbo.LineFaultDescription.FaultCategory, dbo.LineFaultData.Shift
FROM dbo.LineFaultDescription INNER JOIN
dbo.LineFaultData ON dbo.LineFaultDescription.FaultCode = dbo.LineFaultData.FaultCode AND
dbo.LineFaultDescription.AssetID = dbo.LineFaultData.AssetID
and (StartTime < '{@End Date}' and StartTime > '{@Start Date}')

WHERE (dbo.LineFaultData.AssetID = {Asset_ID})
AND (dbo.LineFaultData.Shift = '{@Shift}')
ORDER BY dbo.LineFaultData.StartTime DESC

View 4 Replies View Related

SQL Command Returning Some Incorrect Records

Nov 13, 2006

I am fairly sure that I am just overlooking something, but the following command is returning some incorrect fields. 
SqlDataSource1.SelectCommand = "SELECT ITNBR, (SELECT ITDSC FROM AMFLIBT.ITEMASA WHERE AMFLIBT.ITEMASA.ITNBR = AMFLIBT.ITEMBL.ITNBR) AS ITDSC, SUM(MOHTQ) AS Balance, (SELECT VNDNR FROM AMFLIBT.ITEMASA WHERE AMFLIBT.ITEMASA.ITNBR = AMFLIBT.ITEMBL.ITNBR) AS VENDOR FROM AMFLIBT.ITEMBL WHERE VNDNR = @DDLVNDNR GROUP BY ITNBR, VENDOR"
SqlDataSource1.SelectParameters.Add("ddlvndnr", ddl1.SelectedValue)
I have more code to show, if this looks correct.  Just let me know.
Thanks in advance.

View 2 Replies View Related

Returning Limited Number Of Records!

Jul 8, 2004

I am using ORDER BY NEWID() to return random record from sql database. how do i go about returning only 5 random records instead of all records.

Thanks.

View 2 Replies View Related

Returning Range Of Records In MSSQL

Jan 25, 2005

Hi guys, I need to know if there is a way to select a range of records from a database. Kind of like using SELECT TOP 1000, but I need to be able to specify which records to return. So I imagine it would look like this:



SELECT TOP 2000-5000 * FROM customers WHERE groupid=2 ORDER BY FirstName DESC



Where this statement would return only records 2000 to 5000 of the returned results.

View 2 Replies View Related

T-SQL (SS2K8) :: Returning Multiple TOP Records?

Jul 10, 2014

Here is my setup: I have the following tables -

tblPerson - holds basic person data.
tblPersonHistorical - holds a dated snapshot of the fkPersonId, fkInstitutionId, and fkDepartmentId
tblWebUsers - holds login data specific to a web account, but not every person will have a web account

I want to allow my admins to search for users (persons) with web accounts. They need to be able to search by tblPerson.FirstName, tblPerson.LastName, tblInstitutions.Institution, and tblDepartments.Department. The only way a Person record is joined an Institution or Department record is through many -> many junction table tblPersonHistorical.

People place orders and make decisions in our system. Because people can change institutions and departments, we need an historical snapshot of where they worked at the time they placed an order or made a decision. Of course that means some folks will have multiple historical records. That all works fine.

So when an admin user wants to search for webusers, I only want to return data, if possible, from he most recent/current historical records. This is where I am getting bogged down. When I search for a specific webuser I simply do a TOP 1 and ORDER BY DateCreated DESC. That returns only the current historical record for that person/webuser.

But what if I want to return many different webusers, and only want the TOP 1 historical for each returned?

Straight TOP by itself won't do it.
GROUP BY by itself won't do it.

View 9 Replies View Related

Returning Records Within Days Range

Oct 31, 2013

This is a follow on from one of my earlier threads where I was trying to return one specific record. In this case I am trying to return multiple records for the same person ID and within a number of days range. Snapshot of my date with same PersonID:

PersonID Arrival_Date Leaving_Date ArrivalID
======== ============ ============ =========
123456 01/12/2012 01/12/2013 arr_56464
123456 10/12/2012 10/12/2013 arr_56474
123456 13/12/2012 13/12/2013 arr_56494

And from this I want to check if one record's leaving date of the record is within 7 days of another record's arrival date. I also want to return the record that had a leaving date within 7 days of the next arrival date.I understand that if I self join on personID with the data above I will get 9 rows, for each row I will get 3 matches, I am using INNER JOIN to join to the same table but with a different alias so I assume this is the self join I should be using.

But then how do I process this? I would want to say for record 1 check the leaving date is within 7 days of arrival date of any other record matching that PersonId but not ArrivalID, and return both records.From my snapahot of code I would eventually want to return:

PersonID Arrival_Date Leaving_Date ArrivalID
======== ============ ============ =========
123456 10/12/2012 10/12/2013 arr_56474
123456 13/12/2012 13/12/2013 arr_56494

But can't seem to get this using a self join query like this:

select a.PersonID, a.Leaving_date,a.Arrival_Date,a.arrivalID
from arrivals a INNER JOIN arrivals b
ON b.personID = a.personID
WHERE
a.arrivalid != b.arrivalid
and DATEDIFF(DD, b.[Leaving_date], a.[Arrival_Date]) <=7
and DATEDIFF(DD, b.[Leaving_date], a.[Arrival_Date]) >=0

View 4 Replies View Related

Returning Records That Exclude Top 10% Of Values

Mar 6, 2008

I have data that looks like below (columns are Timestamp, Offered, Answered and Delay). I'm looking to exclude returning records that have a value for Delay that are within the top 10% of values of that column. Are there any 2005 tricks where this can be accomplished in a simple statement?

2008-02-18 08:30:002322173
2008-02-18 08:45:002120174
2008-02-18 09:00:002425230
2008-02-18 09:15:002828277
2008-02-18 09:30:002522159

View 3 Replies View Related

Returning Records Unordered/randomized

May 8, 2008



Hi All,

Let's say I have a SELECT that returns 1000 records and I want them unordered or randomized How would I do that?

So instead of:
OrderID
1
2
3
4
5...and so on

I want:
OrderID
67
300
100
1
910..totally random, but all 1000 records must still be returned.

Regards
Melt

View 10 Replies View Related

Question On Returning All Records When Using Parameters...

May 4, 2007

I'm trying to fully utilize parameters on a report.



I have 3 parameters, a start date, end date, and a cause.



The start and the end date are working as expected. What I would like is if a user fails to select a cause (queried from a lookup dataset) I would like to return all records, not filtering by cause. I'm using parameters handed to the dataset to do this and the report will not allow me not to select a value.



Should I be using Filter, Report Parameters, or some other means to solve this?



Any advice would be appreciated as I don't want to "KLUDGE" up the system with a bunch of reports each with varying levels of criteria.



Thanx!



TR

View 8 Replies View Related

Returning Number Of Records Found In Query

Jan 24, 2008

I am trying to return the number of records found by the query but keep seeing -1 in label1. This query should return many records.
         sub findcustomers(sender as object,e as eventargs)            dim connection1 as sqlconnection=new sqlconnection(...)            dim q1 as string="select * from tblcustomers where store='65'"            dim command1 as sqlcommand=new sqlcommand(q1,connection1)            dim a as integer            command1.connection.open()            a=command1.executenonquery()            label1.text=a.tostring()            command1.connection.close()         end sub
What am I doing wrong?

View 8 Replies View Related

Returning Only Non Matching Left Join Records

Mar 3, 2015

How to return only non matching left join records. Currently I am doing a traffic management database to learn sql.

I am checking for all parishes with no associated drivers. Currently I only have 2 of such.

The regular left join

select parish.name, driver.fname from parish left join driver on driver.parish=parish.name

Returns the all the names of the parishes and the first name of the associated drive, followed by the matches, however the two parishes with no matches have null for the first name.

View 1 Replies View Related







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