Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Need help with creating a view

Need help with creating a view

Scheduled Pinned Locked Moved Database
databasehelptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael J Eber
    wrote on last edited by
    #1

    I'm sending data to a closed, vendor application using views. We have one field (role) that represents the role the user plays. The vendor application exposes three of these roles but only as booleans. This is beyond my SQL skill level....how to I take this one field and return three boolean fields out of it? Thanks, Michael

    D M 2 Replies Last reply
    0
    • M Michael J Eber

      I'm sending data to a closed, vendor application using views. We have one field (role) that represents the role the user plays. The vendor application exposes three of these roles but only as booleans. This is beyond my SQL skill level....how to I take this one field and return three boolean fields out of it? Thanks, Michael

      D Offline
      D Offline
      Dimitri Witkowski
      wrote on last edited by
      #2

      create view view_name as select field_name as f1, field_name as f2, field_name as f3 from table_name this will select a column a 3 duplicated columns

      Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.

      1 Reply Last reply
      0
      • M Michael J Eber

        I'm sending data to a closed, vendor application using views. We have one field (role) that represents the role the user plays. The vendor application exposes three of these roles but only as booleans. This is beyond my SQL skill level....how to I take this one field and return three boolean fields out of it? Thanks, Michael

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        As Dmitry suggested, select the column 3 times. You can also incorporate a case statement to send a 1 or 0 as the value.

        SELECT
        CASE WHEN FieldName = 1 THEN 1 ELSE 0 END F1,
        CASE WHEN FieldName = 2 THEN 1 ELSE 0 END F2,
        CASE WHEN FieldName = 3 THEN 1 ELSE 0 END F3
        FROM TableName

        Never underestimate the power of human stupidity RAH

        M 2 Replies Last reply
        0
        • M Mycroft Holmes

          As Dmitry suggested, select the column 3 times. You can also incorporate a case statement to send a 1 or 0 as the value.

          SELECT
          CASE WHEN FieldName = 1 THEN 1 ELSE 0 END F1,
          CASE WHEN FieldName = 2 THEN 1 ELSE 0 END F2,
          CASE WHEN FieldName = 3 THEN 1 ELSE 0 END F3
          FROM TableName

          Never underestimate the power of human stupidity RAH

          M Offline
          M Offline
          Michael J Eber
          wrote on last edited by
          #4

          Looks like your answer gives me the answer I need. CASE WHEN Role = 1 Then 1 else 0 end IsAdministrator, CASE WHEN Role = 2 Then 1 else 0 end IsDecisionMaker, etc. Thanks, Michael

          1 Reply Last reply
          0
          • M Mycroft Holmes

            As Dmitry suggested, select the column 3 times. You can also incorporate a case statement to send a 1 or 0 as the value.

            SELECT
            CASE WHEN FieldName = 1 THEN 1 ELSE 0 END F1,
            CASE WHEN FieldName = 2 THEN 1 ELSE 0 END F2,
            CASE WHEN FieldName = 3 THEN 1 ELSE 0 END F3
            FROM TableName

            Never underestimate the power of human stupidity RAH

            M Offline
            M Offline
            Michael J Eber
            wrote on last edited by
            #5

            Dimitry -- I now have to add one additional field but this one is harder. Each contact has an AccessGranted table tied to them with the locations they can access. I need to reduce that table down to a boolean CanAccess. How do I do something like that when I don't really have a customer key to work with. This is what my view looks like right now:

            SELECT TOP (100) PERCENT dbo.CustomerMaster.BSACustomerKey, dbo.ContactMaster.ContactName, dbo.ContactMaster.BusinessPhone, dbo.ContactMaster.MobilePhone,
            dbo.ContactMaster.Email, dbo.ContactMaster.FirstName, dbo.ContactMaster.LastName, dbo.ContactMaster.EmergencyMaintenance,
            dbo.ContactMaster.NormalMaintenance, dbo.ContactMaster.NetworkAbuse, dbo.ContactMaster.IssuedSwipeCard, dbo.ContactMaster.CardNumber,
            dbo.AddressList.CustomerAddressLine1, dbo.AddressList.CustomerAddressLine2, dbo.AddressList.CustomerAddressLine3, dbo.AddressList.CustomerPostBox,
            dbo.CityEnumerator.City, dbo.StateEnumerator.State, dbo.AddressList.CustomerCounty, dbo.AddressList.CustomerCountry, dbo.AddressList.CustomerZipcode,
            dbo.ContactMaster.BmcCustKey, CASE WHEN dbo.ContactMaster.Role = 1 THEN 1 ELSE 0 END AS IsAdministrator,
            CASE WHEN dbo.ContactMaster.Role = 6 THEN 1 ELSE 0 END AS IsDecisionMaker,
            CASE WHEN dbo.ContactMaster.Role = 5 THEN 1 ELSE 0 END AS IsAccountingAP
            FROM dbo.ContactMaster INNER JOIN
            dbo.CustomerMaster ON dbo.ContactMaster.CompanyID = dbo.CustomerMaster.CustomerIdentity LEFT OUTER JOIN
            dbo.AddressList ON dbo.ContactMaster.ContactAddress = dbo.AddressList.AddressIdentity LEFT OUTER JOIN
            dbo.CityEnumerator ON dbo.AddressList.CustomerCity = dbo.CityEnumerator.CityIdentity LEFT OUTER JOIN
            dbo.StateEnumerator ON dbo.AddressList.CustomerStateorProvince = dbo.StateEnumerator.StateIdentity
            WHERE (dbo.CustomerMaster.CustomerStatus = 1) AND (dbo.ContactMaster.Status = 1)
            ORDER BY dbo.CustomerMaster.BSACustomerKey

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups