• samn265 - Saturday, June 23, 2018 12:06 PM

    >> Sorry for this dumb question but I am very new to SQL. Could someone help me write a SQL code? <<

    This is not a dumb question; it is a naïve question. If you were learning English for the first time and you had originally started in a language where everything is gendered, our lack of gendered nouns would drive you nuts; if you're from a Slavic language that doesn't have articles, this would be really weird. Or an Asian language that doesn't have plurals. Etc.

    >> I Have Table “A†with 10 columns. Column 9 has any of these four values: “Testâ€, “Holdâ€, “Goâ€, or “Flag†<<

    Let's start over. Obviously 'A' is a terrible name for a table. A table models either a relationship or set of entities and should have an appropriate name for that. Yes, I know you did this for posting, but please get in the habit of always thinking of a table is one of those two things and always using appropriate name, even in your postings. The next mistake, which is really fundamental, is it columns don't have positional numbers in RDBMS. We try to identify everything in this language that we can, by using names. Yes, SQL has some compromises that expand the list of column names in particular orders. Back in the 1980s when I was working on the SQL standards, we really didn't have much choice about this for to be practical. We builds the early SQL engines on top of existing filesystems. But that's another topic

    What we wanted to see was something like this:

    CREATE TABLE Foobars
    ( ....<< needs a key>>
    foobar_status CHAR(4) NOT NULL
     CHECK ('Test', 'Hold', 'Go','Flag' ),
    ..);

    You see how constraints limit the domain of a given value. We also have no idea what the key to this table is. If you truly have no idea whatsoever how RDBMS works, then start off with a copy of the "Manga Guide to Database"; everyone looks at me funny when I recommend this, but it is probably the simplest, most fun if you like Japanese comics, intro to RDBMS.

    >> I would like to make a duplicate copy of any record [sic] where column 9 has a value = “Hold†or “Go†and change it to the value “Step 3â€.<<

    Saying "make a duplicate copy" in SQL or RDBMS is like saying "let's eat fried babies!" To a vegan; it is wrong on so, so many levels. The whole you function of databases, not just SQL, was to remove redundancy not to create duplicates!

    Why did you create this extra "step three" value as what I assumed was a possible status? I used to tell people it took about a year to learn SQL; I'm changing that to about a year to become nothing but a code monkey and about 3-5 years to actually become in RDBMS person. Stick with it, because frankly data is a lot more fun than just procedural code ever was! This is based on several decades of experience 🙂

    Please post DDL and follow ANSI/ISO standards when asking for help.