update query help 08-26-10

ear All

i have following DDL and sample data

[sql 2000]

create table main_tab (t_id varchar(10),fname varchar(30), lname
varchar(30), gender char(1),status smallint)
create table im_tab (t_id varchar(10),flag char(1))

insert into main_tab values('a0101','Ali','Hussain','M',null)
insert into main_tab values('a0102','Noor','Inam',null)
insert into main_tab values('a0103','Siddique','Hussain','M',null)
insert into main_tab values('a0104','Farooq','Ali','M',null)
insert into main_tab values('a0105','Ahmed','Mushtaq','M',null)
insert into main_tab values('a0106','Qurban','Khan','M',null)
insert into main_tab values('a0107','Ahmed','Hasan','M',null)

insert into im_tab values('a0101','a')
insert into im_tab values('a0101','1')
insert into im_tab values('a0101','2')
insert into im_tab values('a0101','3')

insert into im_tab values('a0102','a')
insert into im_tab values('a0102','1')
insert into im_tab values('a0102','2')
insert into im_tab values('a0102','3')

insert into im_tab values('a0103','a')
insert into im_tab values('a0103','1')
insert into im_tab values('a0103','2')

insert into im_tab values('a0104','a')

insert into im_tab values('a0105','1')
insert into im_tab values('a0105','2')
insert into im_tab values('a0105','3')

i want to set status = 1 where  records from main_tab have complete set
of data
in im_table,
like a0101 and a0102 forms complete set in im_table

how can i do that

*** Sent via Developersdex http://www.developersdex.com ***
8/26/2010 7:41:18 PM
sqlserver.programming 1873 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 58

Jami (jami.khan@yahoo.com) writes:
> i want to set status = 1 where  records from main_tab have complete set 
> of data in im_table, 
> like a0101 and a0102 forms complete set in im_table
It's not clear whether the flags has to be exactly those listed, or whether
for instance 'b', 5, 6 and 7 also could be a complete set. This query
assumes that 'a', 1, 2, 3 is the only possibility:

UPDATE main_tab
SET    status = 1
FROM   main_tab m
        FROM   im_tab i 
        JOIN   (SELECT flag = 'a' UNION ALL
                SELECT '1' UNION ALL
                SELECT '2' UNION ALL
                SELECT '3' ) AS u ON i.flag = u.flag
        WHERE  m.t_id = i.t_id) = 4

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

8/26/2010 9:45:13 PM
Look up the term "Relational Division"
8/27/2010 1:12:24 PM

Similar Artilces:

Need help getting files from Exchange Server.
We have a computer that had an account on Outlook attached to a Microsoft exchange server. Apparently for the moment, this computer and the server are inextricably tied together. Outlook cannot even be started without logging into the server because information store or whatever is missing. How do you get the information out of the exchange server to wean the computer from it? tom <Spamblocker@ameritech.net> wrote: > We have a computer that had an account on Outlook > attached to a Microsoft exchange server. > > Apparently for the moment, this computer and the > se...

Project desktop expert, new to Project Server 2007 and working with a sandbox implementation currently. When I use the PWA Build Team...Replace to replace a generic resource on a project with an actual named resource after first publishing a plan, my updates don't appear to be reflected in Project Server. If I check out and open the Project Plan in MSP Pro, however, the updates were made, and then if I publish the schedule, the updates appear in server. I thought when you made resource updates using PWA that they should be reflected immediately (or as soon as the request...

Enable Canadian Tax Detail option should update cost on receipt la
Would like the Enable Canadian Tax Detail option in the Company Setup Options window to work like how Landed Costs work. For example, if I select to post my tax detail to the Inventory account, I would like it to not only update my Inventory account in the General Ledger, but also to update the cost on the Receipt Layer in Inventory so when the Item is sold, it will sell at the Item Unit Cost plus the tax amount. The voucher created in Payables Management would just include the Item Cost without the tax amount. ---------------- This post is a suggestion for Microsoft, and Microsoft re...

Please help, I know nothing
I am a very new at this and it is driving me crazy. For example, I want to add all of column A + column B and I want the answer to go in C. I want this action to always happen automatically. How do I do this...in easy, non-math language?? I understand the basic concept of the formula, but it will only do it in C1, e.g I also get the error #name? Where do I enter this "name" and what is it referring to I would appreciate any and all help Thanks Amme your question is a little vague do you want c1 to add a1 & b1 then c2 to add a2 & b2 If yes then in c1 type in =a1+b1 o...

With a Query in Access 2007, How can I Create This Query
I need a query that will list all records in table 1 for which there are no auditor records (Table 3). Somehow, I need to use the relationship between tables 2 and 3 to find what's not in table 1. The following query gives me a list of all records that do have auditor records. I'm at a dead end on this one. Query SELECT PTOTNamesTbl.PTOTAuditingTherapist, PTOTAuditingTherapist.PTOTFirstName, PTOTAuditingTherapist.PTOTLastName, AuditDetailInitialEval.TherapistLastName, PTOTNamesTbl.PTOTFirstName, PTOTNamesTbl.PTOTLastName, AuditDetailInitialEval.Medicare, AuditDet...

Counting 04-26-07
Hello, I am having difficulty counting numbers within a very large table based on survey results. The table is set as follows subjectname, q1a, q1b, q1c, q1d...q5e Values for each question range from 1-5 and the field could be empty if no response was given. I have tried the something similar to the following and it is not counting correctly. Select subjectname, count(iff(q1a=5 or q1b=5 ... or q5e=5, 1, 0)) from table group by subjectname My desired outcome will be to display the total 5's, Total Responses for the subject (count where the response is in 1-5), and from this I can calcu...

lotus approach queries VS access queries.
Hi, We are migrationg from approach to access. My basic underastanding of the procedure is that the data has to be migrated and all the other features like forms and reports have to be recreated. Is 'Approach query' different from MS Access query? Can this be assumed to be replaced by Access query? cheers, Nuti ...

Help with ActiveX
Hi all. I am just getting my feet wet using MFC and am having trouble with an ActiveX control I created. Essentially, I need an ActiveX control that is a container for local controls. What I have is a set of instruments with slightly different communications needs. My plan is to have separate controls for each instrument so that I can use a single exe for all of them. The exe provides the user interface while the ActiveX provides instrument feedback. There are no input fields on the ActiveX but there are several text fields and a progress bar. I am managing the text fields and progress bar in...

Removal of Outlook 2000 from XP home Help
I am attempting to remove an unauthorized version of Office 2K from a Win XP home computer. The Removal went fairly normal except that now when accessing any E-Mail client, the Windows installer is attemtping to install something from the Win 2K premium disk. Is there a Registery entry causing this problem? Is there a way to stop this from happening? do you know what it's installing and does it fix it if you give it the disk? -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Outlook Tips: ht...

Query cross two table
Hi, I have two tables, tbAdmission and tbCode. In my tbAdmission, I have Code1, Code2 and Code3. In my tbCode, I have Code, Description1 and Description2. In my Form, frmAdmission, I have txtCode1, txtCode2 and txtCode3 that are all bounded to tbAdmission. And txtDescription1Code1, txtDescription2Code1, txtDescription1Code2, txtDescription2Code2, txtDescription1Code3 and txtDescription2Code3 that are unbounded and only for displaying the descriptions. txtCode1, txtCode2 and txtCode3 all refer to Code in tbCode to retrieve Description1 and Description2 for displaying in the unbou...

Help me create sales chart based on state and quantity
We have a production report on excel. It shows the details for our clients. Part of that data includes the state in which the client lives. We are trying to create a chart showing the percentages of each state( so we know where the most deals are closed) Any suggestions? Hello mr_merchant_man, this sounds like a job for a pivot table, using Average as the data calculation operator. Or, depending on your version of Excel, you can use AVERAGEIFS (in Excel 2007) or calculate an averate with a combination of SUMIF divided by COUNTIF. To be more specific, it would help to s...

Help with formula #28
I have an excel spread sheet with formulas that work correctly, when I email them to another person and they open the attachment all looks ok. When they save the excel file to their PC and open it the formula cells now all have #Name in them. Anyone know what is causing this??? The error message gives us a clue: Excel can't find something - things to check: 1. Make sure the receivers all are using the same add-ins as the sender 2. Make sure that personal.xls is the same for the receivers as the sender 3. Make sure all defined names are the same -- Gary's Student "Play...

need help Combo Box with duplicate entry.
I have a combo box with unique and non-unique entries. (search field) 00010 | john | smith | 12345 | 00002 00196 | jane | doe | 0120 | 00001 00196 | Jone| wood| 0220 | 00005 I would like the following to happen. 1) user types the number needed ( 10 ) 2) the combo box zero fills the field (00010) 3) then selects an entry from the combo box. (12345) if the select is incorrect ( one of the non-unique numbers was selected - 00196) the user will open the combo box and select the correct entry. (jone wood) add the info will be put on the form. the following code works if the user ente...

How to get the handle of a Help file belonging to other process.
Hi all, In my application,I want to change the Index of a HTMLHELP file which belongs to a dialog running in other exe.In order to do this I need to find whether the Help file is open or not & get the handle of that to use HH_DISPLAY_INDEX .Is there any way to do this?? Note: I dont want to use FindWindow() as it is giving rise to some problems in my application.. Thanks in advance ...

Help with cells auto formatting
Hi, I have posted a similar question before however I never really got this sorted so sorry for repeating myself. Basically I use two spreadsheets daily at work all with various information on and various formats in each Column. My problem is when I close the spreadsheet and reopen it the cells that are formatted as 'general' or 'number' turn into Euro currencies. Does anyone know why this happens or how I can stop it? The spreadsheets aren't stored locally they are stored on a serve that only myself and my boss can get onto and we both have the same p...

Outlook Express address bk. from Mac to Outlook PC ?? Help
I am trying to export the address bk from my Outlook Express (Mac OS 9.2) to a form that my Outlook PC (Windows XP) can read and use. Any thoughts on what procedure to follow. When I export from the Mac it just saves it as a "Simple text" file - no much good for what I want to do. Any thoughts??? ...

Help on adding values to a bar chart
Hello, Here is my problem. I currently have a bar chart that has 8 X-axis bars. I need to add 2 more to the X-axis. The labels for the x-axis are based on cells within another spreadsheet, but are not consecutive cells, they are spread apart. So when I go to add the two more cells, I can only add one. When I click on the second cell to add it to the list, all of the previous cells get unselected. I have even tried to manually add these two values in. Is there a limit to how many values can be on the X-axis? Please Help!!! Thanks. To select non-consecutive cells: select first cell, h...

Excel spradsheet automation help
there are 3 sheets in an excel spreadsheet say the names are 1,2 AND3 layouts ar ethere for all 3 sheets. the first sheet is used as input and based on certain fields/columns in the first sheet i need to populate entries in the second and 3 rd sheet. teh main purpose is taht based on the first sheet the 2 and 3 sheet should be automatically filled. wat kind of formula / macro should i be using .. im new to this and jsut know to create macro. CAn anybody help ON either Sheet 2 or Sheet 3, you can put this formula in any cell and it will return whatever value is in cell A1 on sheet 1. =Sh...

internet explorer 03-01-10
internet explorer clashed remove and re-install but still cannot what should I do ? I must use Internet explorer "joanna" <joanna@discussions.microsoft.com> wrote in message news:109CCED0-F22D-4B62-A71C-3FCD690BAF5E@microsoft.com... > internet explorer clashed With what? What version of IE? What version of Windows? joanna wrote: > internet explorer clashed > remove and re-install but still cannot > what should I do ? > I must use Internet explorer Very nice poem! Your question does not contain all the required information neede...

Lookup Help
I have a spreadsheet with three tabs. Tab 1 needs to perform summary calculations Tab 2 & 3 are ODBC connections with source data from other files. Tab 2 is a sql query that is a cross tab with columns 1-4 representing row data and then the remaining columns are employee ids with a productivity value in their column. Not all columns have the same value as they correspond to a job/service performed on a specific date. My problem Tab 1, column 2 contains "completion dates from 1/1-current and refreshes based on tab 2 each time it opens. I need a lookup formula that wi...

help with Excel Chart, Series name
Hello, I am using ORACLE OLE2 package to print a series bar graph in excel. I need to rename "Series Name" that comes out in as a char in excel. By defual the series are names as Series1, Series2, Series3,.....SeriesN. How can I access the handle to "Series Name" which help me change its name. Any help will be highly appreciated. Thanks you, Bilal Bilal, Manally, you do this with Chart - Source data - Series tab. There's a series name box. Select the series to be edited in the drop-down at the left first. It may have a cell reference currently in it, or you can...

Date Query 12-07-07
Hello I'm trying to build a query that shows me all records where a field is older than 90 days from today or are null. I've tried using <Now()-"90" Or Is Null but this doesn't give the desired results. What am I getting wrong? Thanks Assumption: Your field is a date field Field: YourDateField Criteria: Is Null Or <DateAdd("d",-90,Date()) Or try dropping the quotes in your expression so it reads Field: YourDateField Criteria: <Now()-90 Or Is Null -- John Spencer Access MVP 2002-2005, 2007 Center for Health Program Development and Management Un...

Help Needed With Write Conflict Error Message.
I have an order form that users open and close on a regular basis. The form is based on a query. On the form are two fields, "TicketPrinted" and "RevisedDate". Most of the time the field "Ticket Printed" has a value in it of "Yes". What I want to be able to do is that if a date is entered into this "RevisedDate" field, OR if the information is changed in this "Revised Date" field, that when the user closed the form, an update query runs that changes the "TicketPrinted" field from the original value of "Yes"...

6/8/2010 Microsoft Office Security Updates failing to install.
All 6 fail to install. Both of the necessary Service Packs are installed on my system. Now what? Just delete them? Kirk MI wrote: > All 6 fail to install. > > Both of the necessary Service Packs are installed on my system. > > Now what? Just delete them? Lack of given information... "Both of the necessary Service Packs" <-- what necessary service packs for what prodcut. I know your subject says "Microsoft Office", but... yeah - there is not just one version of Microsoft Office and you might not even be speaking of Microsoft O...

I Need Help #2
For whatever reason when I import certain text files, the numbers in certain cells come up for example: 24,00 which excel doesn't recognize. How do I tell the spreadsheet that any cell that has two digits after a comma to add another zero at the end? I am not sure if this helps you, but when you select a cell (or range of cells) hit ctrl+1 or go to format/cells the dialog box lets you customize the cell, the first tab is number and this lets you select the type of cell, like number/text etc. under number it let's you select the decimal numbers desired after a comma. Ben >...