Trouble Using DISTINCT Function

Feb 27, 2008

I need to return a single, unique record for each director. In my example here, I'm getting back 5 records for Bossidy because he has 5 records in the Directorships table each with a unique CompID.


SELECT TDirectors.IDDir, TDirectors.DirFName, TDirectors.DirLName, TDirectors.DirLName + ', ' + TDirectors.DirFName AS DirFullName, TDirectors.ExecutiveTitle, TDirectors.DirGender, TDirectors.DirAge, TDirRace.DirRace,
TDirectors.PrincipalCompany AS CompanyName, TDirectorships.CompID
FROM TDirRace RIGHT OUTER JOIN
TDirectors ON TDirRace.IDDir = TDirectors.IDDir RIGHT OUTER JOIN
TDirectorships ON TDirectors.IDDir = TDirectorships.IDDir
WHERE (TDirectors.DirLName='Bossidy')

I thought I could do this but it doesn't work.


SELECT DISTINCT(TDirectors.IDDir)...

Thanks

View 5 Replies


ADVERTISEMENT

Trouble With Sum() Function

Aug 20, 2004

I have a pretty nasty situation in where I have two tables that hold quantity values for an interval of time. One table has an hourly date format while the other is every 5 minutes. I'm using the below t-sql to pull back the summed quantities I need in an HOURLY format; however, it is doubling the MarketQty field becuase it's not summing the qty field from the HE (henwood_extract) table correctly:

Here's a sample of what I'm trying to do.....

imo_meter_data table has records like this


Code:

ID END_DATE QTY
2 2004/08/18 00:05 2
2 2004/08/18 00:10 2.987
2 2004/08/18 00:15 3.1



henwood_extract is like this


Code:

ID END_DT QTY
132 2004/08/18 00:00 6.087
133 2004/08/18 00:00 1



I'm building a comparison tool, so I want the data from the query to return like this:


Code:

MyFDate MarketQty HenwoodQty
2004/08/18 00:00 7.087 7.087



Which would be correct if the sums worked in the query, but what it's looking like is this:


Code:

MyFDate MarketQty HenwoodQty
2004/08/18 00:00 14.174 14.174



Here's the query that I'm using:

Code:

select imo.meter_id, Convert(datetime, cast(datepart(mm, imo.end_date) as varchar)
+ '/' + cast(datepart(dd, imo.end_date) as varchar)
+ '/' + cast(datepart(yyyy, imo.end_date) as varchar)
+ ' ' + cast(datepart(hh, imo.end_date) as varchar)
+ ':00', 120) MyFDate,
sum(imo.qty) MarketQty, sum(he.qty) as HenwoodQty
from imo_meter_data imo, henwood_extract he where
convert(datetime, imo.end_date, 120) between
convert(datetime, '08/18/2004', 120) and
convert(datetime, '08/19/2004', 120) and
convert(datetime, he.end_dt, 120) between
convert(datetime, '08/18/2004', 120) and
convert(datetime, '08/19/2004', 120) and
convert(datetime, he.end_dt, 120) = Convert(datetime, cast(datepart(mm, imo.end_date) as varchar)
+ '/' + cast(datepart(dd, imo.end_date) as varchar)
+ '/' + cast(datepart(yyyy, imo.end_date) as varchar)
+ ' ' + cast(datepart(hh, imo.end_date) as varchar)
+ ':00', 120) and
he.plant_name = 'Brighton Beach' and
he.meter_type = 'ENERGY'
group by imo.meter_id, convert(datetime, cast(datepart(mm, imo.end_date) as varchar)
+ '/' + cast(datepart(dd, imo.end_date) as varchar)
+ '/' + cast(datepart(yyyy, imo.end_date) as varchar)
+ ' ' + cast(datepart(hh, imo.end_date) as varchar)
+ ':00', 120)
order by MyFDate



Any and all help is greatly appreciated.

View 3 Replies View Related

Trouble Using The CONTAINS() Function In Sql Server

Jul 20, 2005

I am having trouble using the CONTAINS function in sqlserver(enterprise manager). I am typing the following:Select *FROM mytableWHERE CONTAINS(myfield,'mystring')This returns the error:Query Designer encountered a MS Design Tools error:ODBC error:[Microsoft][ODBC SQL Server Driver]'CONTAINS' is not arecognizedfunction name.[Microsoft][ODBC SQL Server Driver][SQLServer]Statement(s) couldnot be prepared.According to the T-SQL reference on msdn this is a supported function?Am I typing something incorrectly? If this is not supported, isthere an equivalent to this function? In my field I have some commadelimited values ie 'apple,orange'. So I need to be able to discernwhich records contain orange. The LIKE keyword doesn't seem to workfor this scenario. Any help would be greatly appreciated.

View 3 Replies View Related

Aggregate Function Trouble

Nov 20, 2007

Problem 1:


Suppose I have a table

T( A, B, C, D, E )

I want to retrieve D, E for all rows which have minimum C when we do a group by on A and B. The query would look something like

SELECT D, E FROM T HAVING C = MIN( C ) GROUP BY A, B

Unfortunately, SQL server gives the error that D, E are not in a group by clause. One way is:

SELECT T.D, T.E
FROM
T,
(
SELECT A, B, MIN( C ) AS F FROM T GROUP BY A, B
) AS T1
WHERE
T.A = T1.A AND
T.B = T1.B AND
T.C = T1.F


What I want to know is whether there is a simpler way of doing this or not, kinda like the first illegal query.

Problem 2:

Suppose in the query

SELECT A, B, CASE WHEN C = 'A' THEN 1
WHEN C = 'B' THEN 2 END ORDER

I want to do MIN( ORDER ). The simple way would be

SELECT A, B, MIN( CASE WHEN C = 'A' THEN 1
WHEN C = 'B'' THEN 2 END )

But this gives an error. There is a way:

SELECT T.A, T.B, MIN( T.C ) FROM
(
SELECT A, B, CASE WHEN C = 'A' THEN 1
WHEN C = 'B'' THEN 2 END AS C
) AS T


but I want to know if there is a simpler way to do this (kinda like the first illegal query).

Regards,

id

View 13 Replies View Related

Aggregate Function/Ambiguous Trouble

Nov 18, 2007

I'm a newb and this has been giving me a trouble for a while.



Code Block
SELECT class.classcode, classname, instrFirst, instrLast, csDay, CONVERT(nvarchar(30), csStart, 8), CONVERT(nvarchar(30), csEnd, 8)
FROM class, class_section, instructor
WHERE class.classcode = class_section.classcode
Group By className
Order By classname, csNum;






Msg 8120, Level 16, State 1, Line 1

Column 'class.classCode' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


class and instructor and class_section are their own tables but classcode and instrID are foreign keys on the class_section table. If anyone can explain this as clearly as possible that would be great (the help examples are usually too complicated)

View 6 Replies View Related

SQL Distinct() Function. What Does It Do

Mar 29, 2008

Im reading some guys code and I see the following code
"select distinct(State) from listOFschools;select * from listOFschools"
He is trying to query out states and the schools that are within the state. What exactly is the distinct() function do. and if anyone can tell me, what exactly is he asking to do in this statement

View 6 Replies View Related

Help With Distinct Function.

Oct 11, 2005

I have a query that returns employee names and reservations they updated for a set date. Here's a simplified version:

Select Employee.Name, Reservation.ResID
From Employee INNER JOIN Reservation
ON Employee.EmpID = Reservation.EmpID
Where Reservation.DateModified BETWEEN '200510010000' AND '200510050000'

The problem is each employee can update the same reservation several times but I only want it to display that record once. The distinct statement doesn't work because I want the EmpID to be listed more than once. Thanks.

View 6 Replies View Related

Distinct Option With SUM Function

Dec 14, 2007

Hi,

I have a query with DISTINCT option. If i use DISTINCT option with aggregate function like SUM will it eliminate duplicate values and then sum the values of a column and what is the syntax for it.

EX I have a column for budget

BUDGET
100
350
275
350
100

so if i use DISTINCT SUM(BUDGET) will it eliminate duplicate values and sum the total.

View 3 Replies View Related

Nested Query With Distinct Function

Jan 12, 2015

I need to know how many widgets are located at each factory.

I have a table called "Widgets". The pertinent column(s) are:

Factory UID

By using only this table I can group the results by the FactoryUID to get the answer. However, this table does not tell me the factory name.

I have a table called "Factories". The pertinent column(s) are:

FactoryUID
FactoryName

I can join these two tables by the FactoryUID. But I don't know how to write this query so that my results will look like the following table:

FactoryName Widgets
Factory1 100
Factory2 200
Factory3 300

View 6 Replies View Related

Trouble Porting A Trivially Simple Function - With Declared Variables

Aug 4, 2006

Here is one such function:CREATE FUNCTION my_max_market_date () RETURNS datetimeBEGINDECLARE @mmmd AS datetime;SELECT max(h_market_date) INTO @mmmd FROM holdings_tmp;RETURN @mmmd;ENDOne change I had to make, relative to what I had working in MySQL, wasto insert 'AS' between my variable and its type. Without 'AS', MS SQLinsisted in telling me that datetime is not valid for a cursor; and Iam not using a cursor here. The purpose of this function is tosimplify a number of SQL statements that depend on obtaining the mostrecent datetime value in column h_market_date in the holdings_tmptable.The present problem is that MS SQL doesn't seem to want to allow me toplace that value in my variable '@mmmd'. I could do this easily inMySQL. Why is MS SQL giving me grief over something that should be sosimple. I have not yet found anything in the documentation for SELECTthat could explain what's wrong here. :-(Any ideas?ThanksTed

View 6 Replies View Related

Trouble Calling Function In View && Multi-Table Select...

Aug 13, 2007

How Do I fix View(below) or Multi-Table select(below) to use this Function to return distinct rows via qcParent_ID?

Following Function populates a field (with concat list of related titles) with other required fields:

Create Function [dbo].openItemsIntoList(@Delimeter varchar(15),@qcparent_ID varchar(1000))

Returns Varchar(8000) as

Begin

Declare @Lists as varchar(8000);



Select @Lists = '';

Select @Lists = @Lists + itemTitle + @Delimeter From z_QClocate_openAll_Qualifier

Where @qcParent_ID = qcParent_ID;

Return Substring(@Lists,1,len(@Lists)-len(@Delimeter));

End

works perfect against single table select (returning 54 distinct rows by qcParent_ID):

Select a.qcParent_ID, a.Facility, a.Modality, openItemListToFix

From dbo.a2_qcEntryForm a

JOIN (Select DISTINCT qcParent_ID, dbo.openItemsIntoList(' / AND ',qcParent_ID) as openItemListToFix FROM dbo.a3_qcItems2Fix) i

on a.qcParent_ID = i.qcParent_ID

But data is needed from 3 tables...
- Created a VIEW that returns all (82) rows (negating distinct of the function on qcParent_ID)
- Failed Miserably Integrating Function call into a multi-table select (inexperienced with complex joins)


This VIEW returns ALL (82) rows in table:


CREATE VIEW z_QClocate_openAll AS

SELECT dbo.a1_qcParent.qcStatus, dbo.a1_qcParent.qcAlert, dbo.a3_qcItems2Fix.qcParent_ID, dbo.a3_qcItems2Fix.qcEntryForm_ID,

dbo.a3_qcItems2Fix.itemComplete, dbo.a3_qcItems2Fix.itemTitle, dbo.a2_qcEntryForm.Facility, dbo.a2_qcEntryForm.Modality

FROM dbo.a1_qcParent INNER JOIN

dbo.a2_qcEntryForm ON dbo.a1_qcParent.qcParent_ID = dbo.a2_qcEntryForm.qcParent_ID INNER JOIN

dbo.a3_qcItems2Fix ON dbo.a2_qcEntryForm.qcEntryForm_ID = dbo.a3_qcItems2Fix.qcEntryForm_ID AND

dbo.a1_qcParent.qcParent_ID = dbo.a3_qcItems2Fix.qcParent_ID

WHERE (dbo.a1_qcParent.qcStatus = 'Awaiting Attn') AND (dbo.a3_qcItems2Fix.itemComplete = 0) OR

(dbo.a1_qcParent.qcStatus = 'In Process') OR

(dbo.a1_qcParent.qcStatus = 'Re-Opened')

Calling like this returns ALL 82 rows (negating the functions distinct):

Select a.qcParent_ID, a.qcStatus, a.qcAlert, a.itemComplete, a.Facility, a.Modality, openItemListToFix

From z_QClocate_openAll a

JOIN (Select DISTINCT qcParent_ID, dbo.openItemsIntoList(' / AND ',qcParent_ID) as openItemListToFix FROM dbo.a3_qcItems2Fix) i

on a.qcParent_ID = i.qcParent_ID

AND THEN THERES...
Failing miserably on Integrating the Function call into This SELECT ON MULTI-TABLES:

How to integrate the Function call:
JOIN (Select DISTINCT qcParent_ID, dbo.openItemsIntoList(' / AND ',qcParent_ID) as openItemListToFix FROM dbo.a3_qcItems2Fix) i

on a.qcParent_ID = i.qcParent_ID

into the multi-table Select relationships (while maintaining Where & Order By):

SELECT dbo.a1_qcParent.qcStatus, dbo.a1_qcParent.qcAlert, dbo.a3_qcItems2Fix.qcParent_ID, dbo.a3_qcItems2Fix.qcEntryForm_ID,

dbo.a3_qcItems2Fix.itemComplete, dbo.a3_qcItems2Fix.itemTitle, dbo.a2_qcEntryForm.Facility, dbo.a2_qcEntryForm.Modality

FROM dbo.a1_qcParent INNER JOIN

dbo.a2_qcEntryForm ON dbo.a1_qcParent.qcParent_ID = dbo.a2_qcEntryForm.qcParent_ID INNER JOIN

dbo.a3_qcItems2Fix ON dbo.a2_qcEntryForm.qcEntryForm_ID = dbo.a3_qcItems2Fix.qcEntryForm_ID AND

dbo.a1_qcParent.qcParent_ID = dbo.a3_qcItems2Fix.qcParent_ID

WHERE (dbo.a1_qcParent.qcStatus = 'Awaiting Attn') AND (dbo.a3_qcItems2Fix.itemComplete = 0) OR

(dbo.a1_qcParent.qcStatus = 'In Process') OR

(dbo.a1_qcParent.qcStatus = 'Re-Opened')


View 3 Replies View Related

Analysis :: Distinct Count Using Filter Function

May 27, 2015

My requirement is to count the customer order number for premium order type orders which has some order quantity.I am using below MDX

count

Filter
(([Customer Order].[Dim Customer Orderkey].[Dim Customer Orderkey].members,
[Outbound Order Attributes].[Order Type].&[P]),[Measures].[Ordered, pcs]>0 ) ,
)

The result is accurate but the query execution time is 3-4 minutes for 10 fact records, when i use multiple dimension. it is showing me 0 valus for this measure for all the members for the dimesion attribute which doen't have any customer order. example it shows all the member of date dimension. is there any way to reduce the rows. i think this is the reason to take more execution time.when i use EXCCLUDEEMPTY the result is NULL

count

Filter
(([Customer Order].[Dim Customer Orderkey].[Dim Customer Orderkey].members,
[Outbound Order Attributes].[Order Type].&[C]),[Measures].[Shipped, pcs]>0 ) ,
EXCLUDEEMPTY)

View 3 Replies View Related

T-SQL (SS2K8) :: Function To List Distinct Pax Name And Ticket Numbers?

Mar 14, 2014

I have data in a table Item_TB that I need to extract in a way that pulls out the distinct pax name and all the ticket numbers associated with the passenger per booking reference.

The data is:

Branch Folder ID Pax TktNo BookingRef
HQ 123 1 Jim 4444 ABCDE
HQ 123 2 Bob 5555 ABCDE
HQ 123 3 Jim 6666 ABCDE
HQ 123 4 Bob 7777 ABCDE
HQ 124 1 Jenny 8888 FGHIJ
HQ 124 2 Jenny 9999 FGHIJ
HQ 124 3 Jenny 3333 FGHIJ

I somehow need to get a function to pull the data out for each booking ref like so

--BookingRef ABCDE
Jim 4444/
6666
Bob 5555
7777
--BookingRef FGHIJ
Jenny 8888/
9999/
3333

I know I can get a simple function to return the all data, but I do not know how to only include the pax name once.

View 4 Replies View Related

Select DISTINCT On Multiple Columns Is Not Returning Distinct Rows?

Jul 6, 2007

Hi, I have the following script segment which is failing:

CREATE TABLE #LatLong (Latitude DECIMAL, Longitude DECIMAL, PRIMARY KEY (Latitude, Longitude))

INSERT INTO #LatLong SELECT DISTINCT Latitude, Longitude FROM RGCcache



When I run it I get the following error: "Violation of PRIMARY KEY constraint 'PK__#LatLong__________7CE3D9D4'. Cannot insert duplicate key in object 'dbo.#LatLong'."



Im not sure how this is failing as when I try creating another table with 2 decimal columns and repeated values, select distinct only returns distinct pairs of values.

The failure may be related to the fact that RGCcache has about 10 million rows, but I can't see why.

Any ideas?

View 2 Replies View Related

Trying To Add A NON-DISTINCT Field To A DISTINCT Record Set In A Query.

Mar 12, 2007

I need to run a SELECT DISTINCT query acrossmultiple fields, but I need to add another field that is NON-DISTINCTto my record set.Here is my query:SELECT DISTINCT lastname, firstname, middleinitial, address1,address2, city, state, zip, age, genderFROM gpresultsWHERE age>='18' and serviceline not in ('4TH','4E','4W')and financialclass not in ('Z','X') and age not in('1','2','3','4','5','6','7','8','9','0')and (CAST (ADMITDATE AS DATETIME) >= DATEDIFF(day, 60, GETDATE()))ORDER BY zipThis query runs perfect. No problems whatsoever. However, I need toalso include another field called "admitdate" that should be treatedas NON-DISTINCT. How do I add this in to the query?I've tried this but doesn't work:SELECT admitdateFROM (SELECT DISTINCT lastname, firstname, middleinitial, address1,address2, city, state, zip, age, gender from gpresults)WHERE age>='18' and serviceline not in ('4TH','4E','4W')and financialclass not in ('Z','X') and age not in('1','2','3','4','5','6','7','8','9','0')and (CAST (ADMITDATE AS DATETIME) >= DATEDIFF(day, 60, GETDATE()))ORDER BY zipThis has to be simple but I do not know the syntax to accomplishthis.Thanks

View 2 Replies View Related

DISTINCT To ShortDateString, Not DISTINCT To The DateTime; How?

May 8, 2006

Hello,
I have written a small asp.net application, which keeps record of the proposals coming from the branch offices of a bank in a tableCREATEd as a TABLE Proposals ( ID smallint identity(7,1), BranchID char(5), Proposal_Date datetime )
This app also calculates the total number of proposals coming from a specific branch in a given date bySELECTing COUNT(BranchID) FROM Proposals WHERE BranchID=@prmBranchID AND Proposal_Date=@prmDateand prints them in a table (my target table).
This target table has as many rows as the result of  the "SELECT COUNT( DISTINCT Proposal_Date ) FROM Proposals"and excluding the first column which displays those DISTINCT Proposal_Dates, it also has as many columns as the result of the"SELECT DISTINCT BranchID FROM Proposals". This target table converts the DateTime values ToShortDateString so that we are able to see comfortably which branch office has sent how many proposals in a given day.
So far so good, and everything works fine except one thing:
Certain DateTime values in the Proposals table which are of the same day but of different hours (for ex: 11.11.2005 08:30:45 and11.11.2005 10:45:30) cause some trouble in the target table,  where "SELECT COUNT( DISTINCT Proposal_Date ) FROM Proposals" is executed, because (as you might already guess) it displays two identical dates in ShortDateString form, and this doesn't make much sense (i.e. it causes redundant rows)
What I need to do is to get a result like (in a neat fashion :)
"SELECT COUNT( DISTINCT Proposal_Date ) <<DISTINCT ONLY IN THE DAYS AND NOT IN HOURS OR MINUTES OR SECONDS>> FROM Proposals"
So, how to do it in a suitable way?
Thanks in advance.

View 4 Replies View Related

How To Show Distinct Rows Of The Column Of The Dataset And Number Of Distinct Rows Of That Column

Mar 29, 2007

suppose i have aDataset with 11 rows. field1 with 5 rows of aaa, 6 rows of "bbb"

I want's some thing like

field1 rowcount
aaa 5
bbb 6

View 1 Replies View Related

Distinct Values Among Distinct Column Values

Jan 9, 2015

Okay, I've been working on this for a couple of hours with no success. I'm trying to find the number of telephone numbers that are associated with multiple students at different school sites. I've created a temp table that lists all phone numbers that are associated with more than one student. I'm now trying to query that table and count the number of telephone numbers that are associated with more than one site. Essentially, I'm looking for parent/guardians that have students at different sites.

Here's an example of what I'm hoping to accomplish:

*In this example, I'm just trying to get a count of the different/distinct school sites associated with each number. If I can, at the same time, limit it to a count of > 1 (essentially excluding parents with students at the same site), even better :)

===================================
Temp table
===================================
SCHOOL | STU_ID | STU_PHONE
101 | 12345 | 111-222-3333
101 | 23456 | 111-222-3333
102 | 34567 | 111-222-3333
101 | 45678 | 999-888-7777
101 | 56789 | 999-888-7777
101 | 67890 | 555-555-5555
102 | 78901 | 555-555-5555
103 | 89012 | 555-555-5555

==================================
Wanted query results
==================================
STU_PHONE | #Students | UNIQUE_SCHOOLS
111-222-3333 | 3 | 2
999-888-7777 | 2 | 1
555-555-5555 | 3 | 3

View 1 Replies View Related

Help Convert MS Access Function To MS SQL User Defined Function

Aug 1, 2005

I have this function in access I need to be able to use in ms sql.  Having problems trying to get it to work.  The function gets rid of the leading zeros if the field being past dosn't have any non number characters.For example:TrimZero("000000001023") > "1023"TrimZero("E1025") > "E1025"TrimZero("000000021021") > "21021"TrimZero("R5545") > "R5545"Here is the function that works in access:Public Function TrimZero(strField As Variant) As String   Dim strReturn As String   If IsNull(strField) = True Then      strReturn = ""   Else      strReturn = strField      Do While Left(strReturn, 1) = "0"         strReturn = Mid(strReturn, 2)      Loop   End If  TrimZero = strReturnEnd Function

View 3 Replies View Related

In-Line Table-Valued Function: How To Get The Result Out From The Function?

Dec 9, 2007

Hi all,

I executed the following sql script successfuuly:

shcInLineTableFN.sql:

USE pubs

GO

CREATE FUNCTION dbo.AuthorsForState(@cState char(2))

RETURNS TABLE

AS

RETURN (SELECT * FROM Authors WHERE state = @cState)

GO

And the "dbo.AuthorsForState" is in the Table-valued Functions, Programmabilty, pubs Database.

I tried to get the result out of the "dbo.AuthorsForState" by executing the following sql script:

shcInlineTableFNresult.sql:

USE pubs

GO

SELECT * FROM shcInLineTableFN

GO


I got the following error message:

Msg 208, Level 16, State 1, Line 1

Invalid object name 'shcInLineTableFN'.


Please help and advise me how to fix the syntax

"SELECT * FROM shcInLineTableFN"
and get the right table shown in the output.

Thanks in advance,
Scott Chang

View 8 Replies View Related

A Function Smilar To DECODE Function In Oracle

Oct 19, 2004

I need to know how can i incoporate the functionality of DECODE function like the one in ORACLE in mSSQL..
please if anyone can help me out...


ali

View 1 Replies View Related

Using RAND Function In User Defined Function?

Mar 22, 2006

Got some errors on this one...

Is Rand function cannot be used in the User Defined function?
Thanks.

View 1 Replies View Related

Pass Output Of A Function To Another Function As Input

Jan 7, 2014

I need to be able to pass the output of a function to another function as input, where all functions involved are user-defined in-line table-valued functions. I already posted this on Stack Exchange, so here is a link to the relevant code: [URL] ...

I am fairly certain OUTER APPLY is the core answer here; there's *clearly* some way in which does *not* do what I need, or I would not get the null output you see in the link, but it seems clear that there should be a way to fool it into working.

View 5 Replies View Related

I Want A Function Like IfNull Function To Use In Expression Builder

Jul 24, 2007

Hi,

I wonder if there a function that i can use in the expression builder that return a value (e.g o) if the input value is null ( Like ifnull(colum1,0) )



i hope to have the answer because i need it so much.



Maylo

View 7 Replies View Related

Boy Am In Big Trouble!!!

Feb 16, 2004

I just got finished developing the company intranet site and thinking that everything was working I boasted about how good it was by getting my boss to login and submit a new job to the db (new job, its a work management app) while i did the same, the pland was to hit the submit button at the same time. He would send one to be read by me and I would send one to be read by him. We both hit submit and the following happened.

The db has somehow fused the two into one. I thought maybe we were to accurate in hitting the submit button together. But I even gave a five second delay between and for some reason the job is being overriden by one user tor the other. In other words we are both sharing the same jobid. I thought this could never happen with sql server supposing that it would lock one request until another was completed and vice versa. But I'm so new to this that I'm just so naieve to think that the db would do this for you. Problem is I'm about to move on and I can't leave the app in this state. Can anyone point to some articles or give some suggestions has to my situation. Most desperately in need!!

Thanks in advance

View 11 Replies View Related

Trouble Getting My Sp Done

May 20, 2006

hello

i'm having touble getting my sp done. the problem is as follow..i've found an sp tokenize (which works fine) with the following signature:

CREATE PROCEDURE TOKENIZE (
S VARCHAR(10000),
DELIM CHAR(1))
RETURNS (
ID INTEGER,
TKN VARCHAR(10000))
AS
DECLARE VARIABLE I INTEGER;
DECLARE VARIABLE LEN INTEGER;
DECLARE VARIABLE FIRSTCHAR CHAR(1);
DECLARE VARIABLE S2 VARCHAR(10000);
begin
...
SUSPEND;
end^

then i build myself another sp (which also works fine) with this signature:

CREATE PROCEDURE GET_DICENTRIES_BY_ASDSKRPT (
ASDSKRPTINPUT VARCHAR(15))
RETURNS (
ID BIGINT)
AS
begin
...
suspend;

end^

now, what i'm trying to do is write another sp (get_dicentries_by_all_asdskrpts) that accepts a '.'-tokenized string as a parameter (e.g. 'bla.bli.blo.blu'; number of tokens NOT fixed at 4!) and returns the intersection of

GET_DICENTRIES_BY_ASDSKRPT('bla'), GET_DICENTRIES_BY_ASDSKRPT('bli'), GET_DICENTRIES_BY_ASDSKRPT('blo') AND GET_DICENTRIES_BY_ASDSKRPT('blu')

does any of you have an idea how to go about?

thanx,

martin

View 1 Replies View Related

Sql Trouble

Jul 23, 2005

Could someone help me get the following SQL statement working?SELECTstandardgame.gamename,standardgame.rowteamname,standardgame.colteamname,standardgame.dollarvalue,standardgame.gameid,standardgame.cutoffdatetime,standardgame.gametype,standardgame.gameowner,(100-COUNT(purchasedsquares.gameid)) AS squaresremainingFROM standardgameLEFT OUTER JOINpurchasedsquares ON standardgame.gameid = purchasedsquares.gameidwhere gametype='$gametype' and dollarvalue = '$dollarvalue' andgameowner = 'GROUP BY standardgame.gameidorder byCASE squaresremaining WHEN 0 THEN 1 ELSE 0 END ASC,squaresremaining ASCThe problem is... MySQL doesn't seem to want to let me usesquaresremaining in that case statement since it's not an officialcolumn name. Any idea how I can reference squaresremaining in the casestatement?

View 2 Replies View Related

Trouble With LIKE

Mar 13, 2007

I have a smalldatetime field in SQL.

 

For the query of my report, I need any transaction that is like 09/2006 (matching the month and year).

So I wrote something like this:

AND (DATE LIKE '%2006%')

That correctly returns all of the 2006 transactions.

Now why won't this work:

AND (DATE LIKE '%2006-09%')

Or how about this:

AND (DATE LIKE '%09%2006%')

 

What is the correct syntax??

View 3 Replies View Related

I'm In Trouble!!

Nov 2, 2007

am an ASP.net developer and i've stucked in a C# windows application ... and i am the linking part ... between the Database and my application ... in ASP i have a wizard that handles getting the data from the controls ... but is it the same in C# windows application ? am using VS2005 TeamSystem... and widows Vista(framework 3.0) .... and this query is getting executed and return 1 ... and the intellecence is telling me to insert 4 strings


int rowseffected = loginNamesTableAdapter.InsertQuery(textBox1.Text.ToString(), textBox2.Text.ToString(), textBox3.Text.ToString(), textBox4.Text.ToString());
MessageBox.Show(rowseffected.ToString());
i don't know how to link the parameters with the controls ... please show me how ... thx... please help with images ... as i previously mentioned... this is a new experment in C# thx.


__________________
Ahmed Reda

View 1 Replies View Related

Trouble With My 1st Connection

Jul 24, 2006

 Using Vs2005 sqlServer 2005 When i try to connect i get this error: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Connection string: <connectionStrings> <add name="pubsConnectionString1" connectionString="Data Source=.;Initial Catalog=pubs;User=mk;pw=x" providerName="System.Data.SqlClient" /> </connectionStrings> Calling code : try { using (SqlConnection cn = new SqlConnection(WebConfigurationManager.ConnectionStrings[0].ConnectionString)) { cn.Open(); } } catch (Exception ex) { Response.Write(ex.Message); }

View 1 Replies View Related

Having Trouble With LIKE In Query

Mar 2, 2007

I have a table adapter query with a like clause that I can't get to work.  The field is "Type", so I have "LIKE '%@Type%'".  When I click the Execute Query button to test, not only does nothing get returned, I don't get the chance to enter the parameter.  If I change LIKE '%@Type%' to say, LIKE '%book%', the appropriate records are returned.  I actually need to check two parameters.  If I ad the second parameter, the where clause becomes(Type LIKE '%@Type%') AND (SendState = @SendState)When I test the query, a screen pops up to let me enter the state, but not the Type.  I can't see anything wrong with the query, but something must be. Diane 

View 4 Replies View Related

Trouble Connectiong

Jun 6, 2007

I am having a most frustrating time getting this working. I have two machines, one named 'REMOTE' and it contains my SQL Server (2005 developer edition). Then I have my main PC, named 'DOUGAL' The server instance on the REMOTE computer is called 'SQLSERVER' and there is only one instance. The server is showing as running etc and I can log in locally on the REMOTE computer easily via the Microsoft SQL Server Management Studio etc. I have two logins that are working fine, sa and a login called 'db_user'.Now I am trying to connect in the server explorer in visual studio. When I try and connection i get the following error; An Error has occured while establishing a connection to the server. When connectiong to SQL Server 2005 this failure may be caused by the fact that under the default settings SQL server does not allow remote connections. (provder: Named Pipes Provider, error: 40 - Count not open connection to SQL Server).  I have tried connection to 'REMOTE/SQLSERVER' 'REMOTE' and with its IP address to - without any luck. So, to fix this problem I have checked that remote connections are allowed (and restarted the system). I have also checked that named pipes and tcp/ip connections are enabled. I have searched around with the aid of my best friend, Google. However, I've only found suggestions that involve trying the fixes I already tried. 

View 4 Replies View Related

Trouble With If Command

Nov 6, 2007

 Ok, what I am tryin to do is quite simple i do believe.  Basically I have an aspx page with a textbox, a button and a datagrid linked to my sql db.  What I am wanting is for a user to enter in their Social Security Number in the text box and click the button.  If the SSN matches a record in the DB then it binds to the datagrid and shows it, IF no match is found then it displays a link to click on to continue onto the next page.  This is to stop duplicate entries.  I can get one to work by itself but not both of them at the same time.  Here is my code.<%@ Page Language="VB" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><script language="VB" runat="server">    Sub btnSearch_OnClick(sender as Object, e as EventArgs)        Dim objConnection As SqlConnection        Dim objCommand    As SqlCommand        Dim objAdapter    As SqlDataAdapter        Dim objDataSet    As DataSet        Dim strSearch     As String        Dim strSQLQuery As String                ' Get Search         strSearch = txtSearch.Text                ' If there's nothing to search for then don't search        ' o/w build our SQL Query and execute it.        If Len(Trim(strSearch)) > 0 Then                                                      OK, Here is my first IF, this works.            ' Set up our connection.            objConnection = New SqlConnection("Data Source=BRADBLACKBUR-PCMSSMLBIZ;" _    & "Initial Catalog=Victorypoint;Integrated Security=True;")                        ' Set up our SQL query text.            strSQLQuery = "SELECT FirstName, LastName, SSN " _    & "FROM Applicants " _    & "WHERE SSN LIKE '%" & Replace(strSearch, "'", "''") & "%' " _    & "ORDER BY SSN;"            ' Create new command object passing it our SQL query            ' and telling it which connection to use.            objCommand = New SqlCommand(strSQLQuery, objConnection)            ' Get a DataSet to bind the DataGrid to            objAdapter = New SqlDataAdapter(objCommand)            objDataSet = New DataSet()            objAdapter.Fill(objDataSet)                                    If objDataSet.Tables.Count < 1 Then                     Right here is where I am having the problem, I need to count the Rows not the Tables, but I dont know what code i should use here.                Button1.Visible = True            Else                ' DataBind DG to DS                dgSearch.DataSource = objDataSet                dgSearch.DataBind()                objConnection.Close()                        End If        End If                    End Sub

View 2 Replies View Related







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