Hi
I have a T-SQL like :
Code Snippet
select * from customers for xml PATH , ROOTand how to save the result to a xml file .
Refer to Books Online about using BCP.
Look in Books Online, Topic: 'BCP Utility'
Hi
I have a T-SQL like :
Code Snippet
select * from customers for xml PATH , ROOTand how to save the result to a xml file .
Refer to Books Online about using BCP.
Look in Books Online, Topic: 'BCP Utility'
Thanks for any help,
BobBob, what is the actual problem? What does how the numbers display
have to do with the sort order? Do you want the negatvie numbers and
the positive values to sort alike? ABS function? Round in select list
but not in the order by?
Perhaps a sample SQL and output would help someone provide the right
solution.
HTH -- Mark D Powell --|||Bob Bryan (RobertGBryanREMOVETHIS@.yahoo.com) writes:
> I am using a select statement to obtain a result set back with
> aggregated data. The problem is that I am seeing column data with 11 to
> 13 digits after the decimal point. I tried using the STR function, but
> then the Order By clause does not sort properly because there are
> negative numbers in the aggregated data... I tried using Round, but
> that does no good either - it still ends up displaying too many digits
> after the decimal point. Right now I'm just using Query Analyzer to
> display the data, so I can live with it for now. But, in the future, my
> app will be getting a result set back and I would prefer not to have to
> go through each row and do a round on it from the program. Does anyone
> know how to solve this problem?
If I could understand the problem, maybe I could solve it. :-)
It sounds as if you are working with floats, which are approxamite
numbers. You can round a value, but you may still see many decimals,
because there may be no exact represenation of the number. You could
convert to decimal, which is a precise type. You could also consider
handling the formatting of the data in the client.
But without knowledge about your data and their data types it's difficult
to say anything more intelligent.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||"Mark D Powell" <Mark.Powell@.eds.com> wrote in message
news:1106753337.073272.7040@.z14g2000cwz.googlegrou ps.com...
> Bob, what is the actual problem? What does how the numbers display
> have to do with the sort order? Do you want the negatvie numbers and
> the positive values to sort alike? ABS function? Round in select list
> but not in the order by?
> Perhaps a sample SQL and output would help someone provide the right
> solution.
> HTH -- Mark D Powell --
Ok, here is my query:
select [TS Bars Back] as BB, [TS Bars Within] as BW,
str([TS Move %], 6, 4) as "Move %", str([TS Entry %], 6, 4) as "Entry T",
str([TS ATR Profit], 7, 2) as "P Goal", sum([P/L Comm]) as "P/L $",
str(sum(Risk), 7, 2) as "Risk",
str(avg([P/L Avg %]), 7, 2) as "P/L %",
str(sum([P/L %]), 10, 2) as "P/L % Sum",
str(avg([P/L Long]), 7, 4) as "Long $", str(avg([P/L Short]), 7, 4) as
"Short $",
Count([# of trades]) as "# Runs", Sum([# of trades]) as "# Trades",
str(sum([Max Drawdown]), 10, 2) as "Max $ DD"
from [Table1].dbo.SumResults
where Symbol = 'GE_1/1m' and [SE Time] = 3600 and [TS Entry %] = .005 and
[TS ATR Stop] = 0
group by [TS Move %], [TS Entry %], [TS Bars Within], [TS Bars Back], [TS
ATR Profit]
order by [P/L $] desc
The output looks like this:
BB BW Move % Entry T P Goal P/L $ Risk
P/L % P/L % Sum Long $ Short $ # Runs # Trades Max $ DD
30 8 0.0075 0.0050 1.20 1452.6800537109375 0.30
1.82 7.26 1191.44 261.240 1 4
429.07
30 8 0.0075 0.0050 1.30 1452.6800537109375 0.30
1.82 7.26 1191.44 261.240 1 4
429.07
So, you can see that the str function works well to limit the # of decimal
points displayed for the other fields.
However, if I use it for the "P/L $" field, then the sort does not come out
right because the order by sorts based
upon the resulting character string and not the number in the field. I need
to limit the number of digits displayed in
the P/L $ field without affecting the sort order. Anybody know how to do
that?
Bob|||Thank you for the idea of using a decimal field instead of a float. Most of
my columns are floats (or reals). So, I tried doing a cast of the real
column to a decimal and it worked like a charm.
For those interested in the syntax, this is what worked:
sum(cast ([P/L Comm] as decimal(10,3))) as "P/L $",
Thanks again,
Bob
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns95EB168E856Yazorman@.127.0.0.1...
> Bob Bryan (RobertGBryanREMOVETHIS@.yahoo.com) writes:
> > I am using a select statement to obtain a result set back with
> > aggregated data. The problem is that I am seeing column data with 11 to
> > 13 digits after the decimal point. I tried using the STR function, but
> > then the Order By clause does not sort properly because there are
> > negative numbers in the aggregated data... I tried using Round, but
> > that does no good either - it still ends up displaying too many digits
> > after the decimal point. Right now I'm just using Query Analyzer to
> > display the data, so I can live with it for now. But, in the future, my
> > app will be getting a result set back and I would prefer not to have to
> > go through each row and do a round on it from the program. Does anyone
> > know how to solve this problem?
> If I could understand the problem, maybe I could solve it. :-)
> It sounds as if you are working with floats, which are approxamite
> numbers. You can round a value, but you may still see many decimals,
> because there may be no exact represenation of the number. You could
> convert to decimal, which is a precise type. You could also consider
> handling the formatting of the data in the client.
> But without knowledge about your data and their data types it's difficult
> to say anything more intelligent.
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp
Is there any way to Rollback Committed Update statement in SQL Server
You could get one of the third party transaction log tools, such as Lumnigent's Log Explorer, and undo the transaction.
SQL Server itself does not have that capability. Once committed, done.
Hi, dear friends,
How can we return the result by filtering tuples with null values? (e.g. I want to return the result for tuples specified by dimention DimA, measures B,C. therefore I want to filter the result with nulls values of B,C for DimA).
Hope it is clear for your help.
And I am looking forward to hearing from you shortly for your help.
Thanks a lot.
With kind regards,
Yours sincerely,
It depends what you mean by "filter" - do you want the null values included or excluded?
And what does B,C mean? Do you mean if either is null or both?
The following is one solution if you want to return members from DimA where both measures are empty (null).
Filter(DimA.members, IsEmtpy(Measures.B) AND IsEmpty(Measures.C)
but I would expect somthing like this could be faster as it could use block computation instead of cell-by-cell evaluation.
INTERSECT(NonEmpty(DimA.Members, Measures.B),NonEmpty(DimA.members, Measures.C))
|||Hi, Darren,
Thanks a lot for your help.
With kind regards,
Yours sincerely,
Hi, dear friends,
How can we return the result by filtering tuples with null values? (e.g. I want to return the result for tuples specified by dimention DimA, measures B,C. therefore I want to filter the result with nulls values of B,C for DimA).
Hope it is clear for your help.
And I am looking forward to hearing from you shortly for your help.
Thanks a lot.
With kind regards,
Yours sincerely,
It depends what you mean by "filter" - do you want the null values included or excluded?
And what does B,C mean? Do you mean if either is null or both?
The following is one solution if you want to return members from DimA where both measures are empty (null).
Filter(DimA.members, IsEmtpy(Measures.B) AND IsEmpty(Measures.C)
but I would expect somthing like this could be faster as it could use block computation instead of cell-by-cell evaluation.
INTERSECT(NonEmpty(DimA.Members, Measures.B),NonEmpty(DimA.members, Measures.C))
|||Hi, Darren,
Thanks a lot for your help.
With kind regards,
Yours sincerely,
-- tblContact
-- (
-- SSN char(9),
-- FirstName varchar(50),
-- LastName varchar(50)
-- )
-- This table contains 500 rows.
Select * from tblContact -- Return only rows 5 through 10
Thanks"Briniken" <briniken@.yahoo.com> wrote in message
news:68dae6d3.0311012131.6f9faf26@.posting.google.c om...
> How can a SQL statement be written to return a specified range of
> rows? For example:
> -- tblContact
> -- (
> -- SSN char(9),
> -- FirstName varchar(50),
> -- LastName varchar(50)
> -- )
> -- This table contains 500 rows.
> Select * from tblContact -- Return only rows 5 through 10
> Thanks
Data in tables doesn't have any order, so you have to decide how to say
which are the 'first' 10 rows. Assuming that you want rows 5 to 10 when
ordered by LastName, then this is one possible solution:
select top 5 * from
(
select top 10 *
from tblContact
order by LastName asc) dt
order by LastName desc
Alternatively, you can look at the first example in this KB article:
http://support.microsoft.com/defaul...kb;en-us;186133
If you add "having count(*) between 5 and 10" to the query, you should also
get the results you want.
Simon|||Hi
There is not equivalent of a row number in SQL Server, therefore you need to
be able to order the values, but something like
SELECT TOP 5 SSN. FirstName, LastName FROM
( SELECT TOP 10 SSN. FirstName, LastName FROM tblContact ORDER BY SSN ASC )
A
ORDER BY SSN DESC
Will give you the rows, but not in order!
Also check out the solution in the following thread
http://groups.google.com/groups?hl=...Newsposts%2BTOP
John
"Briniken" <briniken@.yahoo.com> wrote in message
news:68dae6d3.0311012131.6f9faf26@.posting.google.c om...
> How can a SQL statement be written to return a specified range of
> rows? For example:
> -- tblContact
> -- (
> -- SSN char(9),
> -- FirstName varchar(50),
> -- LastName varchar(50)
> -- )
> -- This table contains 500 rows.
> Select * from tblContact -- Return only rows 5 through 10
> Thanks
I hope you could help me in retrieving the last inserted ID(Auto-Number) then perform another Insert Statement?
I would really much appreciate it. I am coding in VB and am uisng
Visual Web Developer 2005 Express Edition and Microsoft SQL Sever
Management Studio Express.
Thanks alot.
-- Sam
My Codes:
Dim SQLStr5 As String = "INSERT INTO
NotesDetails(Notes_Level,Notes_Subject,Notes_Type,Notes_Year,Notes_Desc)
VALUES ('" & ddl_level.SelectedValue & "','" &
ddl_sub.SelectedValue & "','" & rbl_type.SelectedValue &
"','" & ddl_year.SelectedValue & "','" & tb_desc.Text &
"')"
Dim con5 As New SqlConnection(connstring)
con5.Open()
Dim cmd5 As New SqlCommand(SQLStr5, con5)
cmd5.ExecuteNonQuery()
con5.Close()
'' Need to get last inserted ID to Insert into the next Statement. (Notes_ID)
Dim SQLStr5a As String = "INSERT INTO
NotesComments(Notes_ID,Notes_Comments) VALUES ('" &
ddl_level.SelectedValue & "','" & tb_comments.Text & "')"
Dim con5a As New SqlConnection(connstring)
con5a.Open()
Dim cmd5a As New SqlCommand(SQLStr5a, con5a)
cmd5a.ExecuteNonQuery()
con5a.Close()
The last identity can be fetched using the SCOPE_IDENTITY() function, be aware that you have to do that within the same scope. As an additional new feature of SQL Server 2005 you could use the OUTPUT clause which give you the availbility to return values within the same DML statement. See more informations and samples in the BOL.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de