Click here to Skip to main content
14,737,485 members
Home » Discussions » Database
   

Database

 
QuestionDynamic Query Question Pin
Kevin Marois14-Jul-11 20:01
professionalKevin Marois14-Jul-11 20:01 
AnswerRe: Dynamic Query Question Pin
Blue_Boy14-Jul-11 21:54
MemberBlue_Boy14-Jul-11 21:54 
GeneralRe: Dynamic Query Question Pin
Kevin Marois15-Jul-11 6:34
professionalKevin Marois15-Jul-11 6:34 
GeneralRe: Dynamic Query Question Pin
smcnulty200015-Jul-11 23:31
Membersmcnulty200015-Jul-11 23:31 
AnswerRe: Dynamic Query Question Pin
smcnulty200014-Jul-11 22:53
Membersmcnulty200014-Jul-11 22:53 
AnswerRe: Dynamic Query Question Pin
dasblinkenlight15-Jul-11 18:00
Memberdasblinkenlight15-Jul-11 18:00 
AnswerRe: Dynamic Query Question Pin
PIEBALDconsult16-Jul-11 5:27
professionalPIEBALDconsult16-Jul-11 5:27 
JokeRe: Dynamic Query Question Pin
Mycroft Holmes16-Jul-11 14:06
professionalMycroft Holmes16-Jul-11 14:06 
GeneralRe: Dynamic Query Question Pin
S Douglas11-Aug-11 10:48
professionalS Douglas11-Aug-11 10:48 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult11-Aug-11 15:49
professionalPIEBALDconsult11-Aug-11 15:49 
GeneralRe: Dynamic Query Question Pin
S Douglas12-Aug-11 5:48
professionalS Douglas12-Aug-11 5:48 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult12-Aug-11 18:57
professionalPIEBALDconsult12-Aug-11 18:57 
GeneralRe: Dynamic Query Question Pin
S Douglas13-Aug-11 9:20
professionalS Douglas13-Aug-11 9:20 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult13-Aug-11 10:29
professionalPIEBALDconsult13-Aug-11 10:29 
GeneralRe: Dynamic Query Question Pin
S Douglas13-Aug-11 23:30
professionalS Douglas13-Aug-11 23:30 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult13-Aug-11 8:15
professionalPIEBALDconsult13-Aug-11 8:15 
QuestionUPDATE Multiple tables on one filed. [modified] Pin
Member 808202113-Jul-11 12:12
MemberMember 808202113-Jul-11 12:12 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Blue_Boy14-Jul-11 0:29
MemberBlue_Boy14-Jul-11 0:29 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Shameel14-Jul-11 1:09
professionalShameel14-Jul-11 1:09 
AnswerRe: UPDATE Multiple tables on one filed. Pin
smcnulty200014-Jul-11 23:39
Membersmcnulty200014-Jul-11 23:39 
AnswerRe: UPDATE Multiple tables on one filed. [modified] Pin
Niladri_Biswas18-Jul-11 3:12
MemberNiladri_Biswas18-Jul-11 3:12 
Hi, I am providing a solution to this problem but ideally you should follow as what Shameel has said..

Let us create 4 tables (one master and three child tables) as under

CREATE TABLE [dbo].[tblmaster](
	[testID] [varchar](50) NULL,
	[Name] [varchar](50) NULL
) ON [PRIMARY]


CREATE TABLE [dbo].[tblChild1](
	[testID] [varchar](50) NULL,
	[Name] [varchar](50) NULL,
	[Age] [int] NULL
) ON [PRIMARY]


CREATE TABLE [dbo].[tblChild2](
	[testID] [varchar](50) NULL,
	[Name] [varchar](50) NULL,
	[Address] [varchar](50) NULL
) ON [PRIMARY]

CREATE TABLE [dbo].[tblChild3](
	[testID] [varchar](50) NULL,
	[Sex] [varchar](6) NULL,
	[Address] [varchar](50) NULL,
	[Phone Number] [varchar](50) NULL
) ON [PRIMARY]

insert into tblmaster
select 's401', 'name10' union all
select 's402', 'name11' union all
select 's403', 'name12' union all
select 's404', 'name14'

insert into tblChild1 
select 's401', 'name20', 20 union all
select 's402', 'name21', 21 union all
select 's403', 'name22', 22 union all
select 's404', 'name23',23

insert into tblChild2 
select 's401', 'name30', 'address30' union all
select 's402', 'name31', 'address31' union all
select 's403', 'name32', 'address32' union all
select 's404', 'name33', 'address33' 

insert into tblChild3 
select 's401', 'male', 'address40','9885446789' union all
select 's402', 'female', 'address41','12345678' union all
select 's403', 'male', 'address42','34567891' union all
select 's404', 'female', 'address43','0986234' 

Select * from tblmaster
Select * from tblChild1
Select * from tblChild2
Select * from tblChild3


Now fire the below query

exec sp_msforeachtable N'
  IF EXISTS(SELECT 1 FROM sys.columns WHERE object_id=OBJECT_ID(''?'') AND name = ''testID'')
    EXEC (''UPDATE ? SET testID= case when testID = ''''s401'''' then ''''I00010'''' 
				      when testID = ''''s402'''' then ''''I00020'''' 
				      when testID = ''''s403'''' then ''''I00030'''' 
				      when testID = ''''s404'''' then ''''I00040'''' 
                                  end'')'

N.B.~
Use this example as a reference for your problem.

Thanks
Niladri Biswas
modified on Tuesday, July 19, 2011 5:48 AM

QuestionCalculate and display a progressive balance Pin
Rameez Raja11-Jul-11 21:48
MemberRameez Raja11-Jul-11 21:48 
AnswerRe: Calculate and display a progressive balance Pin
Corporal Agarn12-Jul-11 5:40
professionalCorporal Agarn12-Jul-11 5:40 
AnswerRe: Calculate and display a progressive balance Pin
smcnulty200014-Jul-11 23:34
Membersmcnulty200014-Jul-11 23:34 
GeneralRe: Calculate and display a progressive balance Pin
Rameez Raja16-Jul-11 23:49
MemberRameez Raja16-Jul-11 23:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.