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. Retreiving Data as XML from MS SQL server

Retreiving Data as XML from MS SQL server

Scheduled Pinned Locked Moved Database
questionhtmldatabasesql-serverwpf
3 Posts 2 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.
  • P Offline
    P Offline
    pelos
    wrote on last edited by
    #1

    <hello, I am trying to develop a simple application to retrieve data from MS SQL server using XML Templates. The application consists of a main HTML page with a form. The form has 3 text box to filter data (ID, name and title). When the user pushes the "submit" button a XML template is loaded and the 3 text box values are passed as parameters: For Example: http://localhost/nwind/template/EmployeesList.xml?EmployeeID=1&Name=Nancy&Title=Sales+Representative&Submit=Go The XML template is this: SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE EmployeeID = @EmployeeID AND FirstName = @Name AND Title = @Title FOR XML AUTO As you can see, the template use the 3 params to filter data. This runs ok if the user sets well the 3 values in the text boxes but if the user leaves a text box blank it does not. What i want to do is a filter: if the user only sets text in a text box the application has to list every employees with this text box value. Could you help me? How can i do this? thank you very much!

    P 1 Reply Last reply
    0
    • P pelos

      <hello, I am trying to develop a simple application to retrieve data from MS SQL server using XML Templates. The application consists of a main HTML page with a form. The form has 3 text box to filter data (ID, name and title). When the user pushes the "submit" button a XML template is loaded and the 3 text box values are passed as parameters: For Example: http://localhost/nwind/template/EmployeesList.xml?EmployeeID=1&Name=Nancy&Title=Sales+Representative&Submit=Go The XML template is this: SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE EmployeeID = @EmployeeID AND FirstName = @Name AND Title = @Title FOR XML AUTO As you can see, the template use the 3 params to filter data. This runs ok if the user sets well the 3 values in the text boxes but if the user leaves a text box blank it does not. What i want to do is a filter: if the user only sets text in a text box the application has to list every employees with this text box value. Could you help me? How can i do this? thank you very much!

      P Offline
      P Offline
      pelos
      wrote on last edited by
      #2

      ok, I have solved my problem. I have changed the XML template. Now, the XML template is this: exec StoreProcedure @EmployeeID, @Name, @Title As you can see, it executes a store procedure and pass it the 3 params. Then, in the store procedure the params are checked and in function of their values a query is executed. Problem: I dont know much about SQL and it must be a query for each one of the possible combinations. I think this is very inefficient. The store procedure is this: CREATE PROCEDURE StoreProcedure @EmployeeID int, @Name nvarchar(30), @Title nvarchar(60) AS IF (@EmployeeID < 1 ) AND (@Name = '') AND (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@Name = '') AND (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE EmployeeID = @EmployeeID ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@EmployeeID < 1 ) AND (@Name = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE Title = @Title ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@EmployeeID < 1 ) AND (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE FirstName=@Name ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@EmployeeID < 1 ) BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE FirstName=@Name AND Title = @Title ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@Name = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE Title = @Title AND EmployeeID = @EmployeeID ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE FirstName = @Name AND EmployeeID = @EmployeeID ORDER BY EmployeeID FOR XML AUTO GOTO FIN END FIN: GO Is there another way to do this more efficiently? Thank you very much!

      X 1 Reply Last reply
      0
      • P pelos

        ok, I have solved my problem. I have changed the XML template. Now, the XML template is this: exec StoreProcedure @EmployeeID, @Name, @Title As you can see, it executes a store procedure and pass it the 3 params. Then, in the store procedure the params are checked and in function of their values a query is executed. Problem: I dont know much about SQL and it must be a query for each one of the possible combinations. I think this is very inefficient. The store procedure is this: CREATE PROCEDURE StoreProcedure @EmployeeID int, @Name nvarchar(30), @Title nvarchar(60) AS IF (@EmployeeID < 1 ) AND (@Name = '') AND (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@Name = '') AND (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE EmployeeID = @EmployeeID ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@EmployeeID < 1 ) AND (@Name = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE Title = @Title ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@EmployeeID < 1 ) AND (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE FirstName=@Name ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@EmployeeID < 1 ) BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE FirstName=@Name AND Title = @Title ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@Name = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE Title = @Title AND EmployeeID = @EmployeeID ORDER BY EmployeeID FOR XML AUTO GOTO FIN END IF (@Title = '') BEGIN SELECT EmployeeID, FirstName, LastName, Title FROM Employees WHERE FirstName = @Name AND EmployeeID = @EmployeeID ORDER BY EmployeeID FOR XML AUTO GOTO FIN END FIN: GO Is there another way to do this more efficiently? Thank you very much!

        X Offline
        X Offline
        Xiangyang Liu
        wrote on last edited by
        #3

        It looks like your stored procedure can be simplified to one select statement: SELECT     EmployeeID, FirstName, LastName, Title FROM     Employees WHERE     (@EmployeeID < 1 or EmpolyeeID = @EmployeeID) and     (@Name = '' or FirstName = @Name) and     (@Title = '' or Title = @Title) ORDER BY     EmployeeID FOR XML AUTO[

        My articles and software tools

        ](http://mysite.verizon.net/XiangYangL/index.htm)

        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