Showing posts with label state. Show all posts
Showing posts with label state. Show all posts

Monday, March 19, 2012

Help with a query

I have a table with 4 relevant fields (blank lines added for clarity).
State, City, Name, Primary_Contact
IL, Springfield, Bill, n
IL, Springfield, Frank, n
IL, Springfield, Larry, n

IL, Bloomington, Steve, n
IL, Bloomington, Chris, y

IL, Chicago, Betty, n
IL, Chicago, Linda, n
IL, Chicago, Sue, n

I need a query to return the state and cities that don't have a
Primary_Contact='y'
So the results would be:
IL, Springfield
IL, Chicago

That's it. Any help is greatly appreciated.--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1

SELECT State, City
FROM table_name
WHERE Primary_Contact<>'y'
GROUP BY State, City

--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRUBYA4echKqOuFEgEQLJTACgsOAgruNlQX254w4Abe/ychTn9IAAn11t
O+xXdFBxIeubcPHE0uh6fyoi
=YNNo
--END PGP SIGNATURE--

foneguy2 wrote:

Quote:

Originally Posted by

I have a table with 4 relevant fields (blank lines added for clarity).
State, City, Name, Primary_Contact
IL, Springfield, Bill, n
IL, Springfield, Frank, n
IL, Springfield, Larry, n
>
IL, Bloomington, Steve, n
IL, Bloomington, Chris, y
>
IL, Chicago, Betty, n
IL, Chicago, Linda, n
IL, Chicago, Sue, n
>
I need a query to return the state and cities that don't have a
Primary_Contact='y'
So the results would be:
IL, Springfield
IL, Chicago
>
That's it. Any help is greatly appreciated.
>

|||On 25 Oct 2006 15:58:36 -0700, foneguy2 wrote:

Quote:

Originally Posted by

>I have a table with 4 relevant fields (blank lines added for clarity).
>State, City, Name, Primary_Contact
>IL, Springfield, Bill, n
>IL, Springfield, Frank, n
>IL, Springfield, Larry, n
>
>IL, Bloomington, Steve, n
>IL, Bloomington, Chris, y
>
>IL, Chicago, Betty, n
>IL, Chicago, Linda, n
>IL, Chicago, Sue, n
>
>I need a query to return the state and cities that don't have a
>Primary_Contact='y'
>So the results would be:
>IL, Springfield
>IL, Chicago
>
>That's it. Any help is greatly appreciated.


Hi foneguy2,

The solution posted by MGFoster won't work, unfortunately. It will give
you all State/City combo's that have at least one Primary_Contact='n'.

Here's the "straightforward" solution:

SELECT DISTINCT a.State, a.City
FROM YourTable AS a
WHERE NOT EXISTS
(SELECT *
FROM YourTable AS b
WHERE b.State = a.State
AND b.City = a.City
AND b.Primary_Contact = 'n');

And here's a more clever (but harder to graps) solution that might run a
bit faster:

SELECT State, City
FROM YourTable
GROUP BY State, City
HAVING MIN(Primary_Contact) = 'n';

(Untested - see www.aspfaq.com/5006 if you prefer a tested reply).

--
Hugo Kornelis, SQL Server MVP|||>I have a table with 4 relevant fields [sic] .. <<

Suggestions:
1) learn why a column is nothing like a field
2) Use a numeric code instead of a fake Boolean flag. That way the
MIN() will give you a contact in every location. I would bet you spend
time updating the flags.

CREATE TABLE Contacts
(state_code CHAR(2) NOT NULL,
city_name CHAR(25) NOT NULL,
contact_name CHAR(25) NOT NULL,
contact_priority INTEGER NOT NULL
CHECK (contact_priority 0),
PRIMARY KEY (state_code, city_name, contact_name, contact_priority));

This will show one contact in every city

CREATE VIEW PrimaryContacts (state_code, city_name, contact_name)
AS
SELECT C1.state_code, C1.city_name, C1.contact_name
FROM Contacts AS C1
WHERE contact_priority
= (SELECT MIN (C2.contact_priority)
FROM Contacts AS C2
WHERE C1.state_code = C2.state_code
AND C1.city_name = C2.city_name);

Wednesday, March 7, 2012

Help Urgent

Hi everyone,
I'm getting this error from a production SQL Server 2000 +
SP3
Error: 7105, Severity: 22, State: 6
Page (1:433348), slot 7 for text, ntext, or image node
does not exist.
I found this article about thte error:
http://support.microsoft.com/default.aspx?scid=kb;en-
us;304847&Product=sql2k
It says that this issue is solved with SP2. I have SP3,
what can i do ' I'm receiving this error right now and
after reading the article i'm afraid that the server
shutdown. Is a critical server to my enterprise. Can
anyone give me any tips for see what's going on and how to
solve it ?
Thanks in advance
MiguelDid you try some diagnosis...mybe try and run DBCC CHECKDB'
-- Miguel wrote: --
Hi everyone,
I'm getting this error from a production SQL Server 2000 +
SP3
Error: 7105, Severity: 22, State: 6
Page (1:433348), slot 7 for text, ntext, or image node
does not exist.
I found this article about thte error:
http://support.microsoft.com/default.aspx?scid=kb;en-
us;304847&Product=sql2k
It says that this issue is solved with SP2. I have SP3,
what can i do ' I'm receiving this error right now and
after reading the article i'm afraid that the server
shutdown. Is a critical server to my enterprise. Can
anyone give me any tips for see what's going on and how to
solve it ?
Thanks in advance
Miguel|||Was the first thing i done, but i did not have the
database name, soo a run dbcc for all databases with no
errors returned. You can see witch database is causing the
error by the message ?

>--Original Message--
>Did you try some diagnosis...mybe try and run DBCC
CHECKDB'
> -- Miguel wrote: --
> Hi everyone,
> I'm getting this error from a production SQL Server
2000 +
> SP3
> Error: 7105, Severity: 22, State: 6
> Page (1:433348), slot 7 for text, ntext, or image
node
> does not exist.
> I found this article about thte error:
> http://support.microsoft.com/default.aspx?scid=kb;en-
> us;304847&Product=sql2k
> It says that this issue is solved with SP2. I have
SP3,
> what can i do ' I'm receiving this error right now
and
> after reading the article i'm afraid that the server
> shutdown. Is a critical server to my enterprise. Can
> anyone give me any tips for see what's going on and
how to
> solve it ?
> Thanks in advance
> Miguel
>.
>

Sunday, February 26, 2012

Help stored procedures

Hello ,

I am in a state of conflict with my c# asp.net web app. Basically i have a stored procedure that updates my customer table with the param supplied, and generates the primary key incrementally. My problem is returning the pk to my asp.net.

Procedure looks like so:

ALTER Procedure newUser (
/* Param List */

@.fname varchar(20),
@.lname varchar(20),
@.address1 varchar(20),
@.address2 varchar(20),
@.city varchar(20),
@.province varchar(20),
@.postalCode varchar(7),
@.country varchar(20),
@.phone varchar(10),
@.email varchar(30),
@.receiveNews bit,
@.archive bit,
@.business varchar(10),
@.fax varchar(10)
)
AS

BEGIN TRANSACTION
INSERT INTO customer (
fname,
lname,
address1,
address2,
city,
province,
postalCode,
country,
phone,
email,
receiveNews,
archive,
business,
fax
)
VALUES (
@.fname,
@.lname,
@.address1,
@.address2,
@.city,
@.province,
@.postalCode,
@.country,
@.phone,
@.email,
@.receiveNews,
@.archive,
@.business,
@.fax
)
COMMIT
RETURN

The syntax has been verified correct and does populate my customers table with valid data.

the column that i wish to return is called "pk_customerId".
I tried using "RETURN pk_customerId" but it gives me an error that the column does not exist even thogh it does.

Any ideas.

Thanks in advancein short, you can do this:

return (scope_identity())

but i'd declare a @.variable and an @.error before your begin tran, then right before your commit do this:

select @.error=@.@.error, @.variable=scope_identity()
if @.error != 0 begin
raiserror ('jkshdk fskjhdf kjshdf jkshdfh', 10, 1)
rollback tran
end
commit
return @.variable