How to filter rows where multiple columns meet criteria, ignoring rows where only some columns meet criteria

Hi All,
Question: How do I filter rows out of a query where multiple columns are equal to a single question mark character?
Background: I'm using SQL 2008 R2.  Furthermore, the part of my brain that helps me create less-than-simple queries hasn't been working for the last 4 days, apparently, and now I need help.
We have about 4,000 rows in a table.  This data set was generated from an exported report, and many of the rows in the detail table were not actual data rows but were simply "header" rows.  For those table rows, most of the columns have
a single question mark as the value.
Some of the detail rows have one or more question mark values, too, so it's important that these rows don't get filtered out.
When I include criteria like "WHERE col1 <> '?' AND col2 <> '?' AND col3 <> '?' AND col4 <> '?'", all rows with a question mark value for even a single one of those columns get filtered out.  How do I filter out rows
where all columns 1-4 contain a question mark value?
Thanks for your help,
Eric

I just tried to create to create a scenario for you. Please see ig you're looking for something like this.
Create table test_Question_mark
RecordID INT identity(1,1),
Col1 varchar(10),
Col2 varchar(10),
Col3 varchar(10),
Col4 varchar(10),
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','??','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','??','??','??')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ??','??','??')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ?','??','??')
--drop table test_Questio_mark
select * from test_Question_mark
select * from test_Question_mark 
WHERE 
(CHARINDEX('?', Col1,1) > 0 AND CHARINDEX('?', Col1, CHARINDEX('?', Col1,1)+1) = 0) AND 
(CHARINDEX('?', Col2) > 0 AND CHARINDEX('?', Col2, CHARINDEX('?', Col2,1)+1) = 0) AND 
(CHARINDEX('?', Col3,1) > 0 AND CHARINDEX('?', Col3, CHARINDEX('?', Col3,1)+1) = 0) AND 
(CHARINDEX('?', Col4,1) > 0 AND CHARINDEX('?', Col4, CHARINDEX('?', Col4,1)+1) = 0) 
--drop table test_Questio_mark
I hope above solution will help.
Thanks!
Ashish.

Similar Messages

  • How to insert chinese fonts in AI and PS? they recognize only some of them

    How to insert chinese fonts in AI and PS? they recognize only some of them

    Since you do not spell out program names, I can't suggest a program forum... but you can find by using the link below
    This forum is actually about the Cloud, not about using individual programs
    Once your program downloads and installs with no errors, you need the program forum
    If you start at the Forums Index http://forums.adobe.com/index.jspa
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says ALL FORUMS) to open the drop down list and scroll

  • Sort  only some columns

    Hello
    As some users asked for this feature, I wrote a short AppleScript doing the job.
    You may grab it from my iDisk:
    <http://idisk.mac.com/koenigyvan-Public?view=web>
    in the folder:
    ForiWork:ForNumbers:
    Download the item: sort_column.zip with a click on the small down arrow displayed near the right edge of the window.
    Yvan KOENIG (from FRANCE lundi 5 mai 2008 10:39:49)

    Something like:
    SQL> CREATE TABLE t (cola NUMBER, colb NUMBER, colc VARCHAR2(10));
    Table created.
    SQL> ALTER TABLE t ADD CONSTRAINT t_unq UNIQUE (cola, colb);
    Table altered.
    SQL> INSERT INTO T VALUES(1,null, 'Cola 1');
    1 row created.
    SQL> INSERT INTO T VALUES(null, 1, 'Colb 1');
    1 row created.
    SQL> INSERT INTO T VALUES(1, null, 'Cola 1');
    INSERT INTO T VALUES(1, null, 'Cola 1')
    ERROR at line 1:
    ORA-00001: unique constraint (OPS$ORACLE.T_UNQ) violatedYou could add NOT NULL constraints for column c and d if required.
    John

  • When creating a "lookup" column be able to display not only one column from the other list, but additional columns

    With the lookup technique, it is possible to select an item from another list and display one column of this item
    It is obviously possible to create several lookup columns on the same list and therefore display several columns
    There’s a high risk of not selecting the same item and therefore have inconsistent columns
    The Requirement therefore consist of being able of displaying several columns of the same item from the other list, based on one unique selection
    Example:
    In list(x), define lookup column on list (y), column Title (possible today)
    Then define a “secondary” lookup column on same list, column Code
    The effect would be that when selecting an item from list (X), both Title and Code would show up consistently in 2 different columns of list (Y)
    All possible solutions are welcomed

    If you are using SharePoint 2010, you can retrieve additional columns when adding a Lookup. If you are using 2007, there is no direct OOTB way, but the following two posts provide potential work-arounds:
    https://www.definitivelogic.com/blog/microsoft-sharepoint-2007-pulling-column-data-one-list-another-based-common-list-field
    http://stefan-stanev-sharepoint-blog.blogspot.com/2010/11/sharepoint-2007-associated-lookup.html
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Gantt view - multiple dates in the same row

    Hi,
    I created gantt view showing employees' vacations. Some of them have their holidays split into several dates (periods). How can I show those multiple dates in the same row in the gantt view? I can only show start date and end date of one vacation, but would
    like to enter multiple periods to be shown in the gantt view, in the same row.
    Thanks.

    You can't using the OOTB gantt chart so you would have to look at custom development or 3rd party web parts.
    Such as (blatant plug but it directly answers the OP question) my own companies Planner web part.
    http://www.pentalogic.net/sharepoint-products/planner
    The By Category view puts timelines on the same row so its ideal for things like vacation planning, room booking etc.
    This page shows it in use.
    http://blog.pentalogic.net/2010/08/sharepoint-staff-vacation-planner-absence-wall-chart-dashboard/

  • Make only few columns drag-able/movable

    I have a requirement where, in a report, I need to make only few columns dragable/movable and the first 3-4 columns as fixed.
    Please let me know if you have any ideas.

    Try Hiding that columns which you don't need.
    Thanks,

  • Change the colour of some column headers

    Hello All,
    I have a table with a few columns. I want to colour some of the column headers. I want to do this as these columns represent a KEY.
    Regards,
    Aayush

    Hi Aayush,
    As such there doesn't exist any way to colour only some column <b>headers</b>. The two existing options are :
    1) Show the data of some columns in a different colour. For this use text views (default one) as the column elements, and select one among the few built-in colours for the property 'semanticColor' of the text view.
    2) Attach a small image to the primary column's header, using the 'imageSource' property of the table header.
    Hope this helps,
    Best Regards,
    Nibu.

  • Refreshing only 1 column in MV (not the full MV)

    Hi,
    I have a MView with several columns and I need to refresh only 1 column in it. Is there a way for doing that? I don't need to refresh complete the MView (which is very time-expensive in my case).
    Database: 10.2.0.3

    There are two options.
    You choose'd, the parameter type as MENU
    you got to use it other way.
    select NAME, CODE from TABLE
    BIP shows,  NAME and internally  CODE will be passed inside the parameter.If you want to show both in MENU format, do this.
    select NAME||CODE "NAME", CODE from TABLEIf you want more Advanced Type LOV,
    Choose, Search in the parameter type.
    it will automatically show all the columns

  • How to transpose rows to multiple dynamic number of columns

    Hi All,
    I have a requirement to transpose the rows in single column to multiple columns. The columns are not fixed.
    A table called XX_PRODUCT_SIZE.
    The data in the table are,
    PRODUCT_NO SIZE PRESSURE
    P1 1 100
    P1 1 200
    P1 2 100
    P1 2 300
    P1 3 300
    The data in the table are not fixed with respect to size and pressure. In future the product P1 may have size 4 with new pressure 900.
    Now I want to convert these rows into multiple columns.
    So it should be,
    PRODUCT_NO SIZE_1 SIZE_2 SIZE_3 PRESSURE_100 PRESSURE_200 PRESSURE_300
    P1 TRUE TRUE TRUE
    P1 TRUE TRUE TRUE
    P1 TRUE TRUE
    I tried many ways of writing using CASE, MAX with rownumber over partition by etc. but which will not work for me as the rows are not fixed to compare.
    Can you please help me writing a query which transpose rows to columns dynamically. My intention is to create a materialized view for this XX_PRODUCT_SIZE table with transposing columns.
    I am using 10g DB
    Thank You
    Manju
    Edited by: ManjuNaik88 on May 28, 2013 2:29 AM

    Hi,
    If the number of columns in a query has to be figured out at run-time, then you need dynamic SQL. See the froum FAQ {message:id=9360005} for links to examples.
    You might find it easier to create one big column that looks like a variable number of columns. SELECT ... PIVOT can do this with XML output. String aggregation is another way; see {message:id=3527823} .
    ManjuNaik88 wrote:
    ... I saw Oracle 11g Pivot can be used. "PIVOT" is still not working
    SELECT ... PIVOT works. If it's not doing what you the way you're uisng it, then just change how you're using it.
    (You don't expect a mor precise answer with just that information, do you?)

  • Custom row-fetch and how to get column values from specific row of report

    Hi -- I have a case where a table's primary key has more than 3 columns. My report on the
    table has links that send the user to a single-row DML form, but of course the automatic
    fetch won't work because 1) I can't set more than 3 item values in the link and 2) the
    auto fetch only handles 2 PK columns.
    1)
    I have written a custom fetch (not sure it's the most elegant, see second question) that is working
    for 3 or few PK columns (it references the 1-3 item values set in the link), but when there are
    more than 3, I don't know how to get the remaining PK column values for the specific row that was
    selected in the report. How can I access that row's report column values? I'll be doing it from the
    form page, not the report page. (I think... unless you have another suggestion.)
    2)
    My custom fetch... I just worked something out on my own, having no idea how this is typically
    done. For each dependent item (database column) in the form, I have a source of PL/SQL
    function that queries the table for the column in question, using the primary key values. It works
    beautifully, though is just a touch slow on my prototype table, which has 21 columns. Is there
    a way to manually construct the fetch statement once for the whole form, and have APEX be smart
    about what items get what
    return values, so that I don't have to write PL/SQL for every item? Because my query data sources
    are sometimes in remote databases, I have to write manual fetch and dml anyway. Just would like
    to streamline the process.
    Thanks,
    Carol

    HI Andy -- Well, I'd love it if this worked, but I'm unsure how to implement it.
    It seems I can't put this process in the results page (the page w/ the link, that has multiple report rows), because the link for the row will completely bypass any after-submit processes, won't it? I've tried this in other conditions; I thought the link went directly to the linked-to page.
    And, from the test of your suggestion that I've tried, it's not working in the form that allows a single row edit. I tried putting this manually-created fetch into a before header process, and it seems to do nothing (even with a hard-coded PK value, just to test it out). In addition, I'm not sure how, from this page, the process could identify the correct PK values from the report page, unless it can know something about the row that was selected by clicking on the link. It could work if all the PK columns in my edit form could be set by the report link, but sometimes I have up to 5 pk columns.
    Maybe part of the problem is something to do with the source type I have for each of the form items. With my first manual fetch process, they were all pl/sql functions. Not sure what would be appropriate if I can somehow do this with a single (page level?) process.
    Maybe I'm making this too hard?
    Thanks,
    Carol

  • BPS: How to filter Lead Columns at run time

    I need to know if there is a way to filter values for lead columns, after planning level and planning package where defined
    Example:
    Family | Material | Brand | Format | sales | cost | Margin
    F1      M1         B1      F1       100     80     20
    F1      M2         B1      F1        95     85     10
    F1      M2         B1      F2       105     90     15
    In this case the user wants to add 10% to sales and review how does it impact into margin, but he wants to apply it only to rows where Material is M1.
    So, he needs to use some kind of filter data (like Excel functionality) to select only the rows corresponding to material M1.
    After that, he wants to perform other filters over the other lead columns, and apply again some changes in the data columns.
    Somebody can help me with this requirement?
    Thanks in advance
    Message was edited by: Pamela Valdivia

    Hi Pamela,
    First of all you would need a variable for Material with Replacement type user defined values to be able to restrict the data for Material M1 when the layout is executed.
    For incrementing the sales by 10% you can create a Planning function which increases the sales amount by 10% and provide a button for the same in the User Planning Folder. You could also restrict the Planning function for Material M1 if you so desire.
    The benefit of the Planning function is that you can always "Undo" the operation if you have not saved/performed a subsequent operation. So as long as the user is applying some changes and undoing the same before the second change step the data is as it is, and for what changes the user would like to simulate you can create a Planning function and provide the option in the Planning folder.
    Hope it helps.
    Cheers
    Anurag

  • SSIS + split 1 row in multiple rows based on multiple columns

    Hi all,
    I have a flat file 
    Shop ID        Check 1        Check 2            Check 3
    500 OK
    OK NOK
    I want to transform this to staging as 3 rows
    Shop ID       Check number 
    Result
    500 1
    OK
    500 2
    OK
    500 3
    NOK
    Anyone can tell me how to tackle this?

    I basically have a table that has the columns I specified
    Shop Check 1
    Check 2 Check 3
    500 OK
    OK NOK
    I now want to actually have them loaded in another table where I have multiple rows for each shop.
    Shop Check
    Result
    500
    1 ok
    500 2
    ok
    500 3
    nok
    So basically I want to go from a column view to a row view. Is this possible?
    In other words, I do see multiple rows for each shop ID which is awesome! But I would like to have instead of the result that number of the check. (1,2,3) with the result next to it :)
    500  OK
    500 OK
    500 NOK

  • Merge multiple rows into single row (but multiple columns)

    How to merge multiple rows into single row (but multiple columns) efficiently.
    For example
    IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
    23 asdc 1 Location USA NM ABQ Four Seasons 87106
    23 asdc 1 Stats 2300 91.7 8.2 85432
    23 asdc 1 Audit 1996 June 17 1200
    65 affc 2 Location USA TX AUS Hilton 92305
    65 affc 2 Stats 5510 42.7 46 9999
    65 affc 2 Audit 1996 July 172 1100
    where different attributes mean different thing for each Information_type.
    For example for Information_Type=Location
    Attribute_1 means Country
    Attribute_2 means State and so on.
    For example for Information_Type=Stats
    Attribute_1 means Population
    Attribute_2 means American Ethnicity percentage and so on.
    I want to create a view that shows like below:
    IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
    23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
    65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
    Thanks

    Hi,
    That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
    I hope this answers your question.
    If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're not formatted. Use \ tags, as described in the forum FAQ, below.)
    Explain, using specific examples, how you get the results you want from the data given.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).  This is always important, but especially so with pivots.
    See the forum FAQ {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Find MIN, MAX of multiple rows from multiple columns

    Hello,
    I need to figure out how to pull the MIN/MAX of multiple rows from multiple columns into one column. Even if some are NULL/blank.
    For Example: (C: Column, R: Row, N - NULL/Blank)
    C:____1____2____3____ 4____Max
    R:____20___22___13____4____*22*
    R:____N____N____32____14___*32*
    R:____N____12____N____N____*12*
    That is, it always gives a value for MIN/MAX unless there are NO values in all the rows of the columns.
    So if there is one value, it will select that for the MIN/MAX, as it's the smallest/biggest since there is nothing to compare it to.
    Here is my current code:
    CASE WHEN COLUMN 1 < COLUMN 2 THEN COLUMN 2 ELSE COLUMN 1 END

    Hi Thank you for your feedback, unfortunately, I just found out that EVALUATE Function is disabled in our environment for security reasons, so the only other way I've discovered is this:
    The problem is that none of the conditions in the case statement are met--so the column is set to null. You can add a WHEN statement (section 2 below) to catch the nulls. There are five cases to consider:
    Case 1: begin insp > bad order
    Case 2: begin insp < bad order
    Case 3: bad order only (begin insp is NULL)
    Case 4: begin insp only (bad order is NULL)
    Case 5: both begin insp is NULL and bad order is NULL
    1) If bgn-crm-insp-ob > report-bo-ob then bgn-crm-insp-ob
    (Case 1)
    CASE WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob') > filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    2) If report-bo-ob is NULL then bgn-crm-insp-ob
    (Case 4, 5) for case 5, you will get NULL
    WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') IS NULL THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    3) Else report-bo-ob
    (Cases 2, 3)
    ELSE filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') END
    Hopefully this works, I'll give feedback if it does, or if you have any further suggestions please submit, again, THANK YOU SO MUCH ANYWAYS!

  • HTML Dataset - how to filter based on data values within columns

    I have had success with using the XML dataset and filtering based on user input (see javascript example below)
    <script type="text/javascript">     
    var ds2 = new Spry.Data.XMLDataSet("disciplinary_actions3.xml", "doh/disciplinary_actions2[type='<? echo($type) ?>'][name>='<? echo($name) ?>']");
    ds2.setColumnType("date-of-sanction", "date");
    </script>
    The XML dataset filters the results based on the type and name values within the XML dataset columns.
    I need to accomplish this type of filtering with an HTML table.  All that I have  been able to accomplish with the use of the in the rowselector (see example below)
    <script type="text/javascript">
    <!--  the setRowSelector filters by the class attribute on the row in the html table
    var ds4 = new Spry.Data.HTMLDataSet("disciplinary_physicians_htmldataset.php", "physician-list");
    ds4.setRowSelector("tr.<? echo($type) ?>");
    ds4.loadData();
    //-->
    </script>
    How can I filter the HTML dataset based on the data VALUES within the table columns and NOT the class or id or span or div,,,etc?
    Although my advanced dataselector within Dreamweaver CS4 has a column selector... I can't under or get it to work.
    Any assistance or direction is greatly appreciated.

    Hi Ron,
    According to your description, you want to pass the Terminal number that user logon to where clause without needing to create a userid table, right?
    As per my understanding, you need to add an additional table to store the user and corresponding terminal, so that you can filter the data to show the rows based on the user and corresponding terminal. Here are some blogs which describe dynamic security
    on tabular model, please see:
    http://blogs.msdn.com/b/himanshu1/archive/2013/03/02/implementing-dynamic-security-in-tabular-models.aspx
    http://www.bidn.com/blogs/ChrisSchmidt/ssas/4332/dynamic-security-in-tabular
    If this is not what you want, there is no other approach to pass the Terminal number that user logon to where clause without needing to create a userid table. Thank you for your understanding.
    Regards,
    Charlie Liao
    TechNet Community Support

Maybe you are looking for

  • My music files aren't missing, but iTunes has randomly lost many of them

    Most of my albums can still be seen in iTunes, but many isolated songs, and occasional whole albums can't be found by iTunes. I get the exclamation mark. When I look for the song files, they are right where they are supposed to be, in many cases righ

  • Transfer data from old hard drive to new G5

    I have an older MAC (IDE) interface and the IO board has gone out. It will no longer power up. I need to somehow copy my data over to a new G5 system. If I understand the specs correctly the new G5 is SATA. Does it also support the IDE drives. What i

  • Camera Raw 5.4 updater funz nicht mit Photoshop CS 3

    Hallo, ich versuche die ganze Zeit das update Camera_Raw_5_4_updater für photoshop cs 3 zu installieren was aber nicht geht. Habe eine Canon EOS 5D Mark II daher brauche ich das update damit ich die Einstellungen vornehmen kann. Mag mir bitte jemand

  • Tracking a purchased iBook

    Greetings, I was wondering if ther was any way to track who purchased a computer using the serial number. I have my friends iBook G4 30Gb drive, 256 Mb RAM and 800MHz processor, combo drive. pretty much the bottom of the line. my question is, he "sai

  • How to make a "plaid" pattern in photoshop

    I've seen the method they use in Photoshop Elements, by using the marquis tool to select a sliver of a photograph and pulling with the Move  tool to stretch it to the length of the page.  How can we do this in Photoshop since the move tool seems to h