Showing posts with label actual. Show all posts
Showing posts with label actual. Show all posts

Monday, March 12, 2012

Retrieving Column Name and Value for each row using GetSchemaTable

I know I can iterate through the schema table using the following.

Can I grab the actual value of each field while looping through the rows and columns?

schemaTable = reader.GetSchemaTable();

foreach (DataRow myDataRow in schemaTable.Rows)

{

foreach (DataColumn myDataColumn in schemaTable.Columns)

{

Console.WriteLine(myDataColumn + "= " + myDataRow[myDataColumn.ColumnName].ToString() );

}

}

An example is if one of the columns in the schema is called Firstname I would like to return:

Row 1

column name = Firstname

value= Bob

column name = Lastname

value= Smith

Row 2

column name = Firstname

value= Greg

column name = Lastname

value= Jones


What about:


int i=0;

foreach (DataRow myDataRow in schemaTable.Rows)

{

Console.WriteLine(string.Format("Row {0}", (string)(i++));

foreach (DataColumn myDataColumn in schemaTable.Columns)

{

Console.WriteLine(string.Format("Column Name = {0}",myDataColumn.ColumnName);

Console.WriteLine(string.Format("value = {0}" , myDataRow[myDataColumn.ColumnName].ToString());

}

}

Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Thanks this works for me.

Wednesday, March 7, 2012

Retrieve REDO Information

I need a way to retrieve INSERT, DELETE and UPDATE information from SQL
Server, which needs to include basically a redo statement such as the actual
INSERT and DELETE statement and an UPDATE statement with the new (set
values) and original values. I know SQL Server has log files and there are
third party applications that an retrieve this information, however some of
them have problems getting the correct or even getting any UPDATE
information, plus I do not need a UI or any of their features, just the
information.
I need to get the INSERT, DELETE and UPDATE information, new and old values
using C++ code. These UI applications are of no use. All I need is the
information.
Oracle has Logminer where you can query the log information based on
operation type and timestamp as well as other useful parameters. DB2 can
even send this information to a message queue.
I need a way to get this information from SQL Server without using database
triggers but using C++ code. It would be nice to be able to query for this
information, similar to Oracle's implementation. Can anyone point me in the
right direction? Thanks in advance for any help you can provide.
Charles ParkerSee my reply in .programming.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Charles Parker" <charles.parker@.whamtect.com> wrote in message
news:e0f%23N2qcGHA.3936@.TK2MSFTNGP05.phx.gbl...
>I need a way to retrieve INSERT, DELETE and UPDATE information from SQL Server, which needs to
>include basically a redo statement such as the actual INSERT and DELETE statement and an UPDATE
>statement with the new (set values) and original values. I know SQL Server has log files and there
>are third party applications that an retrieve this information, however some of them have problems
>getting the correct or even getting any UPDATE information, plus I do not need a UI or any of their
>features, just the information.
>
> I need to get the INSERT, DELETE and UPDATE information, new and old values using C++ code. These
> UI applications are of no use. All I need is the information.
>
> Oracle has Logminer where you can query the log information based on operation type and timestamp
> as well as other useful parameters. DB2 can even send this information to a message queue.
>
> I need a way to get this information from SQL Server without using database triggers but using C++
> code. It would be nice to be able to query for this information, similar to Oracle's
> implementation. Can anyone point me in the right direction? Thanks in advance for any help you can
> provide.
>
> Charles Parker
>

Tuesday, February 21, 2012

Retrieve data using multiple select

Hi everyone

Is is possible to retrieve data using multiple select. Here is my SQL code:

select sum(nPassengers) Planned, Actual, (sum(Planned) - Actual) Variance
from (
select iDeptCode, sum(nPassengers) Planned from tbl_BusRequest
where iReqTime = '1' and iDeptCode = '1' and cReqType = 'I'
group by iDeptCode
and
(Actual = (Select nPassengers from tbl_Riders_NonRiders where dtDate = '11/05/06'
AND cReqType = 'i' and iTimeCode = '1' and iDeptCode = '1' )

Thanksi'm not sure your script will run as written. This is what I can come up with from your code:

select sum(nPassengers) Planned, Actual, (sum(nPassengers) - Actual) Variance from tbl_BusRequest
where iReqTime = '1' and iDeptCode = '1' and cReqType = 'I'

and
(Actual = (Select nPassengers from tbl_Riders_NonRiders where dtDate = '11/05/06'
AND cReqType = 'i' and iTimeCode = '1' and iDeptCode = '1' ))