Thursday, April 16, 2009

Linq

private void foo()

{



string xmlStr =

@"



xml















Code

Message













01

Break

The Payment was not successful





Success

Continue

The Payment was successful







Break



";



string xmlResponse = @"



01

Missing Fields

";



XElement logicElem = XElement.Parse(xmlStr);

XElement responseElement = XElement.Parse(xmlResponse);



var responseCodePath = (from path in logicElem.XPathSelectElements("XMLParsing/NodesToRead/Path")

where path.Attribute("IsResponseCode") != null && bool.Parse(path.Attribute("IsResponseCode").Value)

select path.Value).FirstOrDefault();



string responseCode = (from v in responseElement.XPathSelectElements(responseCodePath)

select v.Value).FirstOrDefault();



string messagePath = (from path in logicElem.XPathSelectElements("XMLParsing/NodesToRead/Path")

where path.Attribute("IsMessage") != null && bool.Parse(path.Attribute("IsMessage").Value)

select path.Value).FirstOrDefault();



string responseMessage = (from v in responseElement.XPathSelectElements(messagePath)

select v.Value).FirstOrDefault();



var matchedResponseActions = from ra in logicElem.XPathSelectElements("ResponseActions/ResponseAction")

where ra.Element("ResponseCode").Value.Equals(responseCode)

|| ra.Element("ResponseCode").Value.Equals(responseCodePath)

select new

{

ResponseCode = ra.Element("ResponseCode").Value,

Action = ra.Element("Action").Value,

Message = ra.Element("Message") == null ? responseMessage : ra.Element("Message").Value

};



var ve = matchedResponseActions.ToList();

}

Wednesday, April 1, 2009

sql , get all stored procedures containing specified string:

sql , get all stored procedures containing specified string:

SELECT Distinct SO.Name

FROM sysobjects SO (NOLOCK)

INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID

AND SO.Type = 'P'

AND SC.Text LIKE '%KEYWORD%'

ORDER BY SO.Name






sql query to get all tables containing specified column



SELECT OBJECT_NAME(object_id)

FROM sys.columns

WHERE name = '';