Solved

Help with SQL pseudo-code

Posted on 2014-04-25
5
2,703 Views
Last Modified: 2014-04-25
Hi,
  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
0
Comment
Question by:tesla764
  • 3
  • 2
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40022864
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...
0
 

Author Comment

by:tesla764
ID: 40022984
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.
Thanks.
0
 

Author Comment

by:tesla764
ID: 40023055
May be I should break this down into smaller individual functions.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40023127
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"
DECLARE @c INT
SELECT @c = COUNT(*) FROM table1 JOIN table2 ON ... WHERE table1.somefield <> table2.somefield
if @c <> 0
begin
   -- do something here
end 

Open in new window


or update some table from those temp tables:
http://www.experts-exchange.com/Database/Miscellaneous/A_1517-UPDATES-with-JOIN-for-everybody.html

reading the high-level description, you actually might want to run a MERGE statement, and not all that complex code:
http://msdn.microsoft.com/de-de/library/bb510625.aspx
0
 

Author Closing Comment

by:tesla764
ID: 40023359
Thanks for your help.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now