Skip to main content

Posts

Showing posts from July, 2011

FOR XML

In a FOR XML clause, you specify one of these modes: RAW - generates a single <row> element per row in the rowset that is returned by the SELECT statement AUTO - generates nesting in the resulting XML by using heuristics based on the way the SELECT statement is specified EXPLICIT -  provides the most flexibility in generating the XML PATH - a simpler alternative to writing EXPLICIT mode queries Examples for RAW:    Query 1:  Basic                       SELECT doc_id ,                                      media_id                       FROM DOC                       FOR XML RAW Result 1:                        <row doc_id="114" media_id="-117" />                       <row doc_id="115" media_id="-113" /> Query 2:  Using Customized name instead of "row" in the result                       SELECT doc_id ,                                      media_id                       FROM DOC                   

Displaying XML file values using SSMS

Reading a value from the XML file and displaying it in SQL DECLARE @MyXML XML SET @MyXML = ' ' 'print convert(nvarchar(500), @MyXML) SELECT a.b.value('a[1]/BibCodingSearch[1]/@CaseID','varchar(10)') AS CaseID, a.b.value('a[1]/BibCodingSearch[1]/@BibCoding_Id','varchar(10)') AS BibCoding_Id, a.b.value('a[1]/BibCodingSearch[1]/@Value','varchar(10)') AS Value, a.b.value('a[1]/BibCodingSearch[1]/@Operator','varchar(10)') AS Operator FROM @MyXML.nodes('xml') a(b) UNION SELECT a.b.value('a[1]/BibCodingSearch[2]/@CaseID','varchar(10)') AS CaseID, a.b.value('a[1]/BibCodingSearch[2]/@BibCoding_Id','varchar(10)') AS CaseIDBibCoding_Id, a.b.value('a[1]/BibCodingSearch[2]/@Value','varchar(10)') AS Value, a.b.value('a[1]/BibCodingSearch[2]/@Operator','varchar(10)') AS Operator FROM @MyXML.nodes('xml') a(b)

XCOPY

Ctrl + C and Ctrl + V is the easiest thing that a person can do in computers ,  but I had the most difficult copy scripts to run. (Well ... I better have an good explanation for wasting so much time in copying stuff over ;P) I had to copy files from one server to another over different domains  ... phew. Thank God that it is over. Writing a simple copy did not help, I used XCOPY. I thought why not share my experience with all, and what better place to share than this. To write a copy script one must keep few things in mind... Keep it simple             xcopy source [destination]                       Destination is not mandatory , if you don't give it then it will copy to the current folder from where you are running the script. Keep every thing in Quotes             xcopy "source" "[destination]"                          Make sure that your source and destination are in quotation marks. That will save you from the horror of not knowing what went wrong