SQL Syntax, Function, Insert data

Hi Experts,
I select the following 3 columns from two tables:

I'm inserting these 3 columns to Table3, where I added a new column, namely ProductId.
So, Table3 has 4 columns: AliasName, HostName, ProductType, ProductId

The content of the ProductId column has to be generated based on what my query returns from the AliasName, HostName, ProductType columns.
For this I would need a function.

This it the pseudo code:
Is ProductType "Vegetable" OR "Dairy" AND HostName start with "PACKAGE"
  If/Validate/Parse that AliasName is 6 HEX digits (0-F)
  Return "AAA.BBB.CCC.AAAAAA.1"+AliasName
Is ProductType "Fruit", "Meat", "Grocery" or "Plants"
 If HostName starts with "USA"
 If/Validate/Parse AliasName is 6 NUMERIC (0-9) digits
Return "AAA.BBB.CCC.BBBBBB.1"+AliasName

Is HostName start with "PACKAGE"
If/Validate/Parse that AliasName is 6 HEX digits (0-F)
Return "AAA.BBB.CCC.CCCCCC.1"+AliasName

If/Validate/Parse that AliasName is 5 or 7 UPPERCASE ALPHA (A-Z)
Return "AAA.BBB.CCC.DDDDDD.1"+AliasName

What is the correct syntax of the query to achieve this. I would appreciate your help.
romsomIT DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
To do the UPPERCASE check, I have to refresh my memory on COLLATE bin values:

    WHEN ProductType IN ('Dairy', 'Vegetable') AND
         HostName LIKE 'PACKAGE%' AND
         AliasName LIKE '[0-9ABCDEF][0-9ABCDEF][0-9ABCDEF][0-9ABCDEF][0-9ABCDEF][0-9ABCDEF]'
    WHEN ProductType IN ('Fruit', 'Grocery', 'Meat', 'Plants') AND
         HostName LIKE 'USA%' AND
         AliasName LIKE '[0-9][0-9][0-9][0-9][0-9][0-9]'
         AliasName LIKE '[0-9ABCDEF][0-9ABCDEF][0-9ABCDEF][0-9ABCDEF][0-9ABCDEF][0-9ABCDEF]'
    WHEN AliasName COLLATE Latin1_General_CS_AS LIKE '[A-Z][A-Z][A-Z][A-Z][A-Z]' OR
         AliasName COLLATE Latin1_General_CS_AS LIKE '[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]' OR
         AliasName COLLATE Latin1_General_CS_AS LIKE '[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]'
END AS AliasName
romsomIT DeveloperAuthor Commented:
Thank you for your quick response. I'm still trying to make it work.
My 4th column name has to be called "ProductId" and the record stored in it has to have the following format:
where XXXX is the AliasName

Is the syntax correct if after THEN I write 'AAA.BBB.CCC.AAAAAA.1.+AliasName' ?
Or is it correct if I write

At the end I should write: END AS ProductId, right?
Scott PletcherSenior DBACommented:
Yes, you've got it exactly right.  Concatenate AliasName and specify the desired column name after the "AS".

WHEN ...
END AS ProductID
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Scott PletcherSenior DBACommented:
So why isn't my answer selected and awarded points since it worked?!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
romsomIT DeveloperAuthor Commented:
Sorry, I viewed it from my cell phone and accidentally I clicked the wrong button. Are the points awarded now? I apologize, my mistake.
Scott PletcherSenior DBACommented:
Yes, sorry, didn't realize you used your phone, that really is rather tricky.  It's all good now.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.