Help with SQL pseudo-code

  Could someone help me put basic SQL pseudo code to perform the following steps?  Can be general. I just need to get the syntax and functional logic in place then I can finish the specifics later.
Thanks in Advance...

- Put counts in temp table
      - 1 for bulk
      - 1 for others
- Verify temp table counts against imported counts
- If not bulk
      - export to mm table
      - Run mm job to import from sql to mm
      - Loop thru temp table for each PP
            - Edit mm job
            - Run mm job
      - Run mm job to export from mm to sql
- If not bulk update IMB for all but pp8
-      Insert records from mm table to live table
            - 1 for bulk
            - 1 for others
- Update live table
            - 1 for bulk
            - 1 for others
- If not bulk create signoff table
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
yes, good idea, to check out each individual sql syntax.

I mean, when you refer to "count", the number of rows of a table would be:
SELECT COUNT(*) FROM yourtable

however, if you want the count of distinct values, or counts as per some "value", the syntax will differ...
to insert that into a temp table INSERT INTO sometable SELECT ...

then: compare with ... in t-sql, you don't just "compare", but you do something ...
for example, if you have 2 rows (same table or different tables is just a matter of syntax...), and you want to "do something" if you have at least 1 "mismatch"
SELECT @c = COUNT(*) FROM table1 JOIN table2 ON ... WHERE table1.somefield <> table2.somefield
if @c <> 0
   -- do something here

Open in new window

or update some table from those temp tables:

reading the high-level description, you actually might want to run a MERGE statement, and not all that complex code:
Guy Hengel [angelIII / a3]Billing EngineerCommented:
as many of the "terms" are not clear to what they refer to, it's unlikely to get anything "good" without just guessing.

for example Put counts in temp table
      - 1 for bulk ...

what does " 1 for bulk " refer to?  I could guess 1 table named "bulk" ...

- Verify temp table counts against imported counts is not clear on what "imported counts" is meaning ? other table? ...

and so on and so forth...
tesla764Author Commented:
All I am trying to see is, for example, what would the SQL code look like to perform...

Put counts in temp table
      - 1 for bulk
      - 1 for others
- Verify temp table counts against imported counts

SQL code to create two temp tables - 1 temp table named bulk and a second named others.
SQL code to verify the temp table counts against counts that are imported, and so on. I need SQL code examples to perform everyone of the listed steps. I will do the fine tuning for our system once I can see how these steps can be coded correctly, including syntax.
tesla764Author Commented:
May be I should break this down into smaller individual functions.
tesla764Author Commented:
Thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.