Showing posts with label address. Show all posts
Showing posts with label address. Show all posts

Friday, March 30, 2012

Question about simple query..

How are you ? Please give me an advice :)
It's been bothering me for three days. I'm new SQL user.

I have the following table, which has name, address, city,state,zip
code, and phone number.

kim 3134 n. chatham ellicott city md 21042
410-222-2222
justin 3134 n. chatham rd. ellicott city md 21042
410-222-2222
hong 4343 antonio ln. ellicott city md 21042
555-341-3412
woo 1123 cedar ln. columbiamd21044 410-111-1358

The problem is that the table should not contain the same phone
number.
Phone number 410-222-2222 is duplicated.

How can I erase that extra data, and get the table like this ? :

kim 3134 n. chatham ellicott city md 21042
410-222-2222
*******************the data that has same phone number is
gone*****************
hong 4343 antonio ln. ellicott city md 21042
555-341-3412
woo 1123 cedar ln. columbiamd21044 410-111-1358

First, I used this query, but it turned out all of my data was gone. :
(

delete FROM address WHERE exists (
select * from address where address.phone = address.phone
);

Please help !What is the criteria that you would use to pic which row to keep?
jaehwang wrote:

Quote:

Originally Posted by

How are you ? Please give me an advice :)
It's been bothering me for three days. I'm new SQL user.
>
I have the following table, which has name, address, city,state,zip
code, and phone number.
>
>
kim 3134 n. chatham ellicott city md 21042
410-222-2222
justin 3134 n. chatham rd. ellicott city md 21042
410-222-2222
hong 4343 antonio ln. ellicott city md 21042
555-341-3412
woo 1123 cedar ln. columbiamd21044 410-111-1358
>
>
The problem is that the table should not contain the same phone
number.
Phone number 410-222-2222 is duplicated.
>
How can I erase that extra data, and get the table like this ? :
>
kim 3134 n. chatham ellicott city md 21042
410-222-2222
*******************the data that has same phone number is
gone*****************
hong 4343 antonio ln. ellicott city md 21042
555-341-3412
woo 1123 cedar ln. columbiamd21044 410-111-1358
>
First, I used this query, but it turned out all of my data was gone. :
(
>
delete FROM address WHERE exists (
select * from address where address.phone = address.phone
);
>
Please help !
>

|||You would have to define a criteria based on which a row will be kept or
deleted (that is another column or combination of columns that is unique).
Here is just an example based on your sample data (in this case the row with
the MIN name will be kept, but this assumes no duplicate names with the same
phone):

DELETE FROM Address
WHERE EXISTS (
SELECT *
FROM Address AS A
WHERE A.phone = Address.phone
AND A.name < Address.name)

You can easily reverse the above condition to A.name Address.name to keep
the MAX name.

After you are done you can alter the table and add UNIQUE constraint on the
phone column to prevent duplicate data in the future, something like this:

ALTER TABLE Address ADD CONSTRAINT uphone UNIQUE (phone)

HTH,

Plamen Ratchev
http://www.SQLStudio.comsql

Monday, March 26, 2012

Question about Parameter

Hi,
I need to design a Sales Order (SO) report for my company. In the SO
report, I need to print out the company name, company address, Telephone no.
... etc in report header. For this design, it serve 5 sub-company under my
company group. Therefore, I store the company data in a table - name
CompanyInfo. Everytime I need to select correct company name to print it out.
But I know that it cannot print "Field" in report header in RS. I try to
put it into parameter and print it out. It OK but all of the parameter will
be show to user. For this point, I don't want our user to see such
information.
Any idea for me?
Thank You!
TonyYou can have multiple datasets in a report. If you put a list at the top of
the report and your query has only one record, then the data will look for
all intents and purposes as the report header. Then following that have your
table or matrix or whatever. I do this all the time and it looks exactly the
same.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Tony" <Tony@.discussions.microsoft.com> wrote in message
news:7DCDBD8B-603D-44EF-B9C2-F409683657F4@.microsoft.com...
> Hi,
> I need to design a Sales Order (SO) report for my company. In the SO
> report, I need to print out the company name, company address, Telephone
> no.
> ... etc in report header. For this design, it serve 5 sub-company under
> my
> company group. Therefore, I store the company data in a table - name
> CompanyInfo. Everytime I need to select correct company name to print it
> out.
> But I know that it cannot print "Field" in report header in RS. I try to
> put it into parameter and print it out. It OK but all of the parameter
> will
> be show to user. For this point, I don't want our user to see such
> information.
> Any idea for me?
> Thank You!
> Tony
>|||Hi Bruce,
Thank you for your reply!
I already try this way and it look OK. But all parameters will be shown at
the top of the report! It looks no good! Can I hidden the parameter? It is
because there are 6 parameters for such report header.
Thank You!
Tony
"Bruce L-C [MVP]" wrote:
> You can have multiple datasets in a report. If you put a list at the top of
> the report and your query has only one record, then the data will look for
> all intents and purposes as the report header. Then following that have your
> table or matrix or whatever. I do this all the time and it looks exactly the
> same.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Tony" <Tony@.discussions.microsoft.com> wrote in message
> news:7DCDBD8B-603D-44EF-B9C2-F409683657F4@.microsoft.com...
> > Hi,
> >
> > I need to design a Sales Order (SO) report for my company. In the SO
> > report, I need to print out the company name, company address, Telephone
> > no.
> > ... etc in report header. For this design, it serve 5 sub-company under
> > my
> > company group. Therefore, I store the company data in a table - name
> > CompanyInfo. Everytime I need to select correct company name to print it
> > out.
> >
> > But I know that it cannot print "Field" in report header in RS. I try to
> > put it into parameter and print it out. It OK but all of the parameter
> > will
> > be show to user. For this point, I don't want our user to see such
> > information.
> >
> > Any idea for me?
> > Thank You!
> >
> > Tony
> >
> >
>
>|||You can have hidden parameters.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Tony" <Tony@.discussions.microsoft.com> wrote in message
news:7FABFC55-8149-4484-9C80-AD70FC318BCF@.microsoft.com...
> Hi Bruce,
> Thank you for your reply!
> I already try this way and it look OK. But all parameters will be shown
> at
> the top of the report! It looks no good! Can I hidden the parameter? It
> is
> because there are 6 parameters for such report header.
> Thank You!
> Tony
>
> "Bruce L-C [MVP]" wrote:
>> You can have multiple datasets in a report. If you put a list at the top
>> of
>> the report and your query has only one record, then the data will look
>> for
>> all intents and purposes as the report header. Then following that have
>> your
>> table or matrix or whatever. I do this all the time and it looks exactly
>> the
>> same.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Tony" <Tony@.discussions.microsoft.com> wrote in message
>> news:7DCDBD8B-603D-44EF-B9C2-F409683657F4@.microsoft.com...
>> > Hi,
>> >
>> > I need to design a Sales Order (SO) report for my company. In the SO
>> > report, I need to print out the company name, company address,
>> > Telephone
>> > no.
>> > ... etc in report header. For this design, it serve 5 sub-company
>> > under
>> > my
>> > company group. Therefore, I store the company data in a table - name
>> > CompanyInfo. Everytime I need to select correct company name to print
>> > it
>> > out.
>> >
>> > But I know that it cannot print "Field" in report header in RS. I try
>> > to
>> > put it into parameter and print it out. It OK but all of the parameter
>> > will
>> > be show to user. For this point, I don't want our user to see such
>> > information.
>> >
>> > Any idea for me?
>> > Thank You!
>> >
>> > Tony
>> >
>> >
>>|||Thank You! I try it!
"Bruce L-C [MVP]" wrote:
> You can have hidden parameters.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Tony" <Tony@.discussions.microsoft.com> wrote in message
> news:7FABFC55-8149-4484-9C80-AD70FC318BCF@.microsoft.com...
> > Hi Bruce,
> >
> > Thank you for your reply!
> >
> > I already try this way and it look OK. But all parameters will be shown
> > at
> > the top of the report! It looks no good! Can I hidden the parameter? It
> > is
> > because there are 6 parameters for such report header.
> >
> > Thank You!
> > Tony
> >
> >
> >
> > "Bruce L-C [MVP]" wrote:
> >
> >> You can have multiple datasets in a report. If you put a list at the top
> >> of
> >> the report and your query has only one record, then the data will look
> >> for
> >> all intents and purposes as the report header. Then following that have
> >> your
> >> table or matrix or whatever. I do this all the time and it looks exactly
> >> the
> >> same.
> >>
> >>
> >> --
> >> Bruce Loehle-Conger
> >> MVP SQL Server Reporting Services
> >>
> >> "Tony" <Tony@.discussions.microsoft.com> wrote in message
> >> news:7DCDBD8B-603D-44EF-B9C2-F409683657F4@.microsoft.com...
> >> > Hi,
> >> >
> >> > I need to design a Sales Order (SO) report for my company. In the SO
> >> > report, I need to print out the company name, company address,
> >> > Telephone
> >> > no.
> >> > ... etc in report header. For this design, it serve 5 sub-company
> >> > under
> >> > my
> >> > company group. Therefore, I store the company data in a table - name
> >> > CompanyInfo. Everytime I need to select correct company name to print
> >> > it
> >> > out.
> >> >
> >> > But I know that it cannot print "Field" in report header in RS. I try
> >> > to
> >> > put it into parameter and print it out. It OK but all of the parameter
> >> > will
> >> > be show to user. For this point, I don't want our user to see such
> >> > information.
> >> >
> >> > Any idea for me?
> >> > Thank You!
> >> >
> >> > Tony
> >> >
> >> >
> >>
> >>
> >>
>
>

Monday, March 12, 2012

Question about design practice - Address table

In a db, is it a good practice to have Address info in Address table in uppe
r
case or lower case?
ex: street name, city, state, county, country etc..
How about name [first name, middle name, last name, prefix, suffix...]
If you have any links that talk in detail about this, I'd like to read them
too
[ Some background: I am looking for some strong points so I could make an
impact in decision making...about best practice]
thanks everyone,
_UdayUsing all lower case for data is terrible. All upper case is bad -
takes me back to my mainframe days when we hardly knew there was a
shift key. I strongly prefer data read by people to be in proper
case: John Smith, Main St, Springfield.
State abbreviations are two character upper case: MA, OH, NY, CT, NJ,
WA.
However, when addresses are printed for the US Postal Service, they
prefer all caps. That change can be made during the printing process,
if at all.
Roy Harvey
Beacon Falls, CT
On Tue, 2 May 2006 12:11:02 -0700, Uday
<Uday@.discussions.microsoft.com> wrote:

>In a db, is it a good practice to have Address info in Address table in upp
er
>case or lower case?
>ex: street name, city, state, county, country etc..
>How about name [first name, middle name, last name, prefix, suffix...]
>If you have any links that talk in detail about this, I'd like to read them
>too
>[ Some background: I am looking for some strong points so I could make an
>impact in decision making...about best practice]
>thanks everyone,
>_Uday|||Default server collation is case in-sensitive.
So first step is, if you are worried about the case. check the collation of
the server,database. and upper case or lower case is a display property and
should be handled in the front end and usually based on requirements.
Hope this helps.|||I agree with you Ron. But the people who make decisions don't see data the
way I see it. So I need some strong points to make an impact on the decision
.
If I just say, 'keep the data in its original format' -- I dont think that'l
l
make a strong point. Hope you can understand the position I am in.
thanks to you all...Ron and Omnibuzz
_Uday
"Roy Harvey" wrote:

> Using all lower case for data is terrible. All upper case is bad -
> takes me back to my mainframe days when we hardly knew there was a
> shift key. I strongly prefer data read by people to be in proper
> case: John Smith, Main St, Springfield.
> State abbreviations are two character upper case: MA, OH, NY, CT, NJ,
> WA.
> However, when addresses are printed for the US Postal Service, they
> prefer all caps. That change can be made during the printing process,
> if at all.
> Roy Harvey
> Beacon Falls, CT
> On Tue, 2 May 2006 12:11:02 -0700, Uday
> <Uday@.discussions.microsoft.com> wrote:
>
>|||Uday.
Few points to remember.
1. If you define some rules saying the names should have the first letter
caps, how are you going to enforce it. Can you prevent a user from inserting
a value that doesn't comply to the standards. You can , by doing a check
constraint with a series of string functions (which SQL Server is not exactl
y
built for). But does it really have any sense to do the check.
Think of SQL Server as a datastore. If the format of storage changes at a
later date (say all caps for the names). How will you enforce the new
standards. Its always better to handle the formatting part in the front end.
That would be my standpoint.
Hope this helps.
--
"Uday" wrote:
> I agree with you Ron. But the people who make decisions don't see data the
> way I see it. So I need some strong points to make an impact on the decisi
on.
> If I just say, 'keep the data in its original format' -- I dont think that
'll
> make a strong point. Hope you can understand the position I am in.
> thanks to you all...Ron and Omnibuzz
> _Uday
> "Roy Harvey" wrote:
>|||it would seem to me that you can only start "doing anything" with the
case in SQL server if you change the collation of the database. I
expect that if used well then this wouldn't be a problem, but I've had
numerous headaches from having to move databases between servers, then
finding the collation is different to the master (which means any SPs
with WHERE colA = 'some value' throw collation conflict errors).
I'd keep with the default collation, it makes everything simpler. As
others have stated, use your front end to do all the validation etc.
then you won't need to wrestle with DTS etc. just to change collation.
Incidentally, I haven't looked into it, but does anyone know if they've
made it easier with 2005 to change a database collation?
Cheers
Will|||You should always store data with as much information contained in it as
possible. You can always convert to all lower or upper or any combination
coming out.
It's like using your digital camera, and saving in a robust (granted, large
file size) on the memory card. You can always shrink it later when you want
to email the pic
Jeff
"Uday" <Uday@.discussions.microsoft.com> wrote in message
news:1162A9EF-6E79-431D-9FF4-FB6FC1AD39F3@.microsoft.com...
>I agree with you Ron. But the people who make decisions don't see data the
> way I see it. So I need some strong points to make an impact on the
> decision.
> If I just say, 'keep the data in its original format' -- I dont think
> that'll
> make a strong point. Hope you can understand the position I am in.
> thanks to you all...Ron and Omnibuzz
> _Uday
> "Roy Harvey" wrote:
>|||Omnibuzz (Omnibuzz@.discussions.microsoft.com) writes:
> 1. If you define some rules saying the names should have the first
> letter caps, how are you going to enforce it. Can you prevent a user
> from inserting a value that doesn't comply to the standards. You can ,
> by doing a check constraint with a series of string functions (which SQL
> Server is not exactly built for). But does it really have any sense to
> do the check.
Yeah, think about Ludwig van Beethoven for example.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks Omnibuzz..!! It sure helps.
I'll try the case-insensitive coallation... and let the data be in which
ever format it is entered. I'll change it on the fly in front-end or as
needed.
Thanks everyone,
_Uday