add an alias field

  • Hi,

    I have a table with products name from a group (1.3.7.2.1).

    All products which has this group are part of a category products (ex: [Grupa] like '1.3." & "%'" are in Electromagnetic_locks category)

    Please tell me how can I filter "group" field and to appear category for each products.

    I atach a png file with my query in sql, please how can I introduce that filter in my sql

    SELECT pozdoccmibtl.Tip, pozdoccmibtl.Cantitate * pozdoccmibtl.Pret_vanzare AS valoare_cantitate, pozdoccmibtl.Data_facturii, pozdoccmibtl.Data_scadentei,

    pozdoccmibtl.Contract, nomencl.Denumire, terti.Denumire AS Client, lm.Denumire AS Loc_munca, terti.Judet, Zone.Denumire_zona, pozdoccmibtl.Factura,

    grupe.Denumire AS [grupe produse], pozdoccmibtl.Cantitate, pozdoccmibtl.Discount, terti.Tert, grupe.Grupa

    FROM pozdoccmibtl INNER JOIN

    nomencl ON pozdoccmibtl.Cod = nomencl.Cod INNER JOIN

    terti ON pozdoccmibtl.Tert = terti.Tert INNER JOIN

    judzone ON terti.Judet = judzone.Judet INNER JOIN

    Zone ON judzone.Zona = Zone.Zona INNER JOIN

    infotert ON pozdoccmibtl.Tert = infotert.Tert INNER JOIN

    lm ON infotert.Loc_munca = lm.Cod INNER JOIN

    grupe ON nomencl.Grupa = grupe.Grupa INNER JOIN

    gestiuni ON pozdoccmibtl.Gestiune = gestiuni.Cod_gestiune

    WHERE (pozdoccmibtl.Tip = 'ap' OR

    pozdoccmibtl.Tip = 'ac') AND (Zone.Denumire_zona = 'ardeal' OR

    Zone.Denumire_zona = 'muntenia si oltenia' OR

    Zone.Denumire_zona = 'moldova si dobrogea' OR

    Zone.Denumire_zona = 'banat crisana' OR

    Zone.Denumire_zona = 'bucuresti')

    thanks a lot.

  • Hi and welcome to the SSC forums.

    If you want to include a description of a group for a code in your table, you'll need to join to the table that contains the group descriptions based on (I think) your [grupa] field. If you don't have such a table, my suggestion would be to create one and then join to it. The alternative would be to hard-code each possible group based on the [grupa] field and that would be a disaster to maintain.

    If you want us to have a chance of being able to write anything, please see the link in my signature on how to post questions. We're going to need consumable DDL to create the structure, DML to create some sample data and your desired output.

  • Ok, I understand, It is more better if I creeate a table with category product, than join it.

    Thanks for your help

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply