Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Expand v.IMP Queriesv.IMP Queries
Collapse XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

Path

 
      
EMP
ID Name Country Salary
1 Vijay India 6000
2 Bill USA 8000
3 Kris France 3000
4 Bhagat India 2000
5 Steve USA 1000

      
SELECT * FROM EMP FOR XML PATH('Country'), ROOT('Root') SELECT p.Country AS "@Name", ( SELECT ID AS "@ID", Name AS "Name", Salary AS "Salary" FROM EMP c WHERE p.Country = c.Country FOR XML PATH('EMP'), TYPE ) FROM ( SELECT DISTINCT Country FROM EMP ) p FOR XML PATH('Country'), ROOT('Root')