PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > with query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
with query

Réponse
 
LinkBack Outils de la discussion
Vieux 14/07/2008, 11h15   #1
jojo123
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with query

Hi

I have a table 1 with postcodes and a flag field that indicates whether it
is welsh.

I have another table (table 2) which has a list of just the first 5
characters of welsh postcodes that I want to use as a lookup table and if
there is a match with the postcode field in table 1 I set the flag field in
table 1 to 1 - how can I formulate the query for this?

Thanks
  Réponse avec citation
Vieux 14/07/2008, 11h24   #2
vinu
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with query



jojo

here is update statement


update t1 set FlagColumn=1 from
table1 t1 inner join table2 t2 on t2.column=left(t1.postcode,5)

vinu


"jojo123" <jojo123@discussions.microsoft.com> wrote in message
news:0853A884-E9C7-46F1-BAE7-C9479E3FE2CB@microsoft.com...
> Hi
>
> I have a table 1 with postcodes and a flag field that indicates whether it
> is welsh.
>
> I have another table (table 2) which has a list of just the first 5
> characters of welsh postcodes that I want to use as a lookup table and if
> there is a match with the postcode field in table 1 I set the flag field
> in
> table 1 to 1 - how can I formulate the query for this?
>
> Thanks



  Réponse avec citation
Vieux 14/07/2008, 11h31   #3
Uri Dimant
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with query


UPDATE [table 1] SET flag=1 FROM
[table 1] t1 JOIN [table 2] t2 ON
SUBSTRING(t1,colname,1,5)=t2.colname
WHERE ........


"jojo123" <jojo123@discussions.microsoft.com> wrote in message
news:0853A884-E9C7-46F1-BAE7-C9479E3FE2CB@microsoft.com...
> Hi
>
> I have a table 1 with postcodes and a flag field that indicates whether it
> is welsh.
>
> I have another table (table 2) which has a list of just the first 5
> characters of welsh postcodes that I want to use as a lookup table and if
> there is a match with the postcode field in table 1 I set the flag field
> in
> table 1 to 1 - how can I formulate the query for this?
>
> Thanks



  Réponse avec citation
Vieux 14/07/2008, 18h09   #4
jojo123
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with query

Thanks for that

Is it possible to update two tables in one update query? something like

update t1, t3 set FlagColumn=1 from
(table1 t1 inner join table2 t2 on t2.column=left(t1.postcode,5)) AND
(table3 t3 innerjoin table2 t2 on t2.column=left(t3.postcode,5))

"vinu" wrote:

>
>
> jojo
>
> here is update statement
>
>
> update t1 set FlagColumn=1 from
> table1 t1 inner join table2 t2 on t2.column=left(t1.postcode,5)
>
> vinu
>
>
> "jojo123" <jojo123@discussions.microsoft.com> wrote in message
> news:0853A884-E9C7-46F1-BAE7-C9479E3FE2CB@microsoft.com...
> > Hi
> >
> > I have a table 1 with postcodes and a flag field that indicates whether it
> > is welsh.
> >
> > I have another table (table 2) which has a list of just the first 5
> > characters of welsh postcodes that I want to use as a lookup table and if
> > there is a match with the postcode field in table 1 I set the flag field
> > in
> > table 1 to 1 - how can I formulate the query for this?
> >
> > Thanks

>
>
>

  Réponse avec citation
Vieux 14/07/2008, 19h25   #5
Tom Cooper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with query

No. An update statement can only update one table.

Tom

"jojo123" <jojo123@discussions.microsoft.com> wrote in message
news:E7FAB0F0-9C95-42F0-99A5-09CA4BC4863F@microsoft.com...
> Thanks for that
>
> Is it possible to update two tables in one update query? something like
>
> update t1, t3 set FlagColumn=1 from
> (table1 t1 inner join table2 t2 on t2.column=left(t1.postcode,5)) AND
> (table3 t3 innerjoin table2 t2 on t2.column=left(t3.postcode,5))
>
> "vinu" wrote:
>
>>
>>
>> jojo
>>
>> here is update statement
>>
>>
>> update t1 set FlagColumn=1 from
>> table1 t1 inner join table2 t2 on t2.column=left(t1.postcode,5)
>>
>> vinu
>>
>>
>> "jojo123" <jojo123@discussions.microsoft.com> wrote in message
>> news:0853A884-E9C7-46F1-BAE7-C9479E3FE2CB@microsoft.com...
>> > Hi
>> >
>> > I have a table 1 with postcodes and a flag field that indicates whether
>> > it
>> > is welsh.
>> >
>> > I have another table (table 2) which has a list of just the first 5
>> > characters of welsh postcodes that I want to use as a lookup table and
>> > if
>> > there is a match with the postcode field in table 1 I set the flag
>> > field
>> > in
>> > table 1 to 1 - how can I formulate the query for this?
>> >
>> > Thanks

>>
>>
>>



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11179 seconds with 13 queries