Showing posts with label column. Show all posts
Showing posts with label column. Show all posts

Thursday, March 29, 2012

Direct Display of SQL Image field

Hi

I have a SQL 2000 table in which pictures are stored as an Image column. I want to display then onto a c# aspx webpage without storing them to disk.
What is the best way to read and display the pictures?
In classic ASP I used to do this:

Response.ContentType = "image/jpeg"
Response.BinaryWrite rs.fields("ThisImage")

but I can't get this to work in c#.Kinda, you should use a <img src="http://pics.10026.com/?src=viewImage.aspx?id=RecordID"> and then use some code like this below to read the database:


using System;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace DBImages
{
/// <summary>
/// Summary description for ViewImage.
/// </summary>
public class ViewImage : System.Web.UI.Page
{
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}

public ViewImage()
{
Page.Init += new System.EventHandler(Page_Init);
}

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
//get the image id from the url
string ImageId =Request.QueryString["img"];
double adjustedSize=Convert.ToDouble(Request.QueryString["size"]);

//build our query statement
string sqlText = "SELECT img_data, img_contenttype FROM Image WHERE img_pk = " + ImageId;

SqlConnection connection = new SqlConnection(ConfigurationSettings.Appsettings["DSN"]);
SqlCommand command = new SqlCommand( sqlText, connection);

//open the database and get a datareader
connection.Open();
SqlDataReader dr;
dr = command.ExecuteReader();

if ( dr.HasRows) //yup we found our image
{
dr.Read();

Response.ContentType = dr["img_contenttype"].ToString();

System.IO.Stream fs=new System.IO.MemoryStream((byte[])dr.GetSqlBinary(0) );
System.Drawing.Image _image=System.Drawing.Image.FromStream( new System.IO.MemoryStream((byte[])dr.GetSqlBinary(0)));

int fileLength, fileWidth, fileHeight;

using(System.Drawing.Image image = System.Drawing.Image.FromStream(fs))
{
fileLength = Convert.ToInt32(fs.Length);
fileWidth = image.Width;
fileHeight = image.Height;
}
double multiplier;

if (fileHeight>fileWidth) // picture must be portrait
{
multiplier=Convert.ToDouble(adjustedSize / fileHeight);
}
else
{
multiplier=Convert.ToDouble(adjustedSize / fileWidth);
}
int newWidth, newHeight;

newWidth=(int)(fileWidth * multiplier);
newHeight=(int)(fileHeight * multiplier);

System.Drawing.Image _newimage=_image.GetThumbnailImage(newWidth,newHeight,null,new System.IntPtr());
_newimage.Save(System.Web.HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.BinaryWrite( (byte[]) dr["img_data"] );

}
connection.Close();
}
}
}
}

I do not comment code. If it was hard to write, it should be hard to read. :) I answer some questions tho.|||Thanks for that

Response.BinaryWrite( (byte[]) dr["img_data"] );
does what I want, and I really appreciate the master class on image manipulation.

Sunday, March 25, 2012

Dimension Name Column Format Property SSAS 2005

I have tried entering different forms of syntax into the 'Format' property underneath the 'Name Column' property for a specific attribute within a dimension and it never seems to change the output when I view the attribute within the 'Browser' tab of the dimension. I tested this on the Adventure Works DW and I am unable to change the attribute format. Here is an example:

1. With the Adventure Works DW, open the 'Employee' dimension and modify the 'Birth Date' attribute's format property underneath name column. I have entered "d", format("DimEmployee"."BirthDate", 'mm/dd/yyyy'), and convert(varchar, "DimEmployee"."BirthDate", 101).

2. Process the dimension and click on the browser tab and view the 'Birth Date' hierarchy.

Has anyone had any luck using this 'Format' property for the 'Name Column' of an attribute? I believe you could easily do this in AS 2000, so I am wondering what the trick is in SSAS 2005. I would think that you could use this property, but I guess I need to know what the proper syntax is. I know that I could easily modify the data source view, but I want to know how to be able to do this in the future if needed.

I have checked on the web and in BOL and haven't found any reference information for this property and how to use it. If anyone knows of any documentation please let me know. I will take a look at the SQL 2008 BOL and see if that has anything new.

Thanks.

I just got a response back from Microsoft and this is what I had kind of figured because no matter what you type in this property it never would produce an error or change the results of the text.

The "Format" string for Attribute names is a stub for a later addon and is not implemented. Attribute names will only accept WChar types. Any formatting should be done either in the data source view as a "Named Calculation" or in the source table/view on the relational source.

Dimension Name Column Format Property SSAS 2005

I have tried entering different forms of syntax into the 'Format' property underneath the 'Name Column' property for a specific attribute within a dimension and it never seems to change the output when I view the attribute within the 'Browser' tab of the dimension. I tested this on the Adventure Works DW and I am unable to change the attribute format. Here is an example:

1. With the Adventure Works DW, open the 'Employee' dimension and modify the 'Birth Date' attribute's format property underneath name column. I have entered "d", format("DimEmployee"."BirthDate", 'mm/dd/yyyy'), and convert(varchar, "DimEmployee"."BirthDate", 101).

2. Process the dimension and click on the browser tab and view the 'Birth Date' hierarchy.

Has anyone had any luck using this 'Format' property for the 'Name Column' of an attribute? I believe you could easily do this in AS 2000, so I am wondering what the trick is in SSAS 2005. I would think that you could use this property, but I guess I need to know what the proper syntax is. I know that I could easily modify the data source view, but I want to know how to be able to do this in the future if needed.

I have checked on the web and in BOL and haven't found any reference information for this property and how to use it. If anyone knows of any documentation please let me know. I will take a look at the SQL 2008 BOL and see if that has anything new.

Thanks.

I just got a response back from Microsoft and this is what I had kind of figured because no matter what you type in this property it never would produce an error or change the results of the text.

The "Format" string for Attribute names is a stub for a later addon and is not implemented. Attribute names will only accept WChar types. Any formatting should be done either in the data source view as a "Named Calculation" or in the source table/view on the relational source.

Thursday, March 22, 2012

difficulty in getting result.

hi all
i am working on sql reporting 2005.
i have 3 reports say A, B ,C
i want to display sum of values in column of A & sum of values in column of B in report C
How can i do this?
plz help me.
report c would have to have the same data as in reports A and B. Then you can sum them.

Wednesday, March 21, 2012

Difficult query: return recordset from concatenated strings?

Hi All,

I have what seems to me to be a difficult query request for a database
I've inherited.

I have a table that has a varchar(2000) column that is used to store
system and user messages from an on-line ordering system.

For some reason (I have no idea why), when the original database was
being designed no thought was given to putting these messages in
another table, one row per message, and I've now been asked to provide
some stats on the contents of this field across the recordset.

A pseudo example of the table would be:

custrep, orderid, orderdate, comments

1, 10001, 2004-04-12, :Comment 1:Comment 2:Comment 3:Customer asked
for a brown model
2, 10002, 2004-04-12, :Comment 3:Comment 4:
1, 10003, 2004-04-12, :Comment 2:Comment 8:
2, 10004, 2004-04-12, :Comment 4:Comment 6:Comment 7:
2, 10005, 2004-04-12, :Comment 1:Comment 6:Customer cancelled order

So, what I've been asked to provide is something like this:

orderdate, custrep, syscomment, countofsyscomments
2004-04-12, 1, Comment 1, 1
2004-04-12, 1, Comment 2, 2
2004-04-12, 1, Comment 3, 1
2004-04-12, 1, Comment 8, 1
2004-04-12, 2, Comment 1, 1
2004-04-12, 2, Comment 3, 1
2004-04-12, 2, Comment 4, 2
2004-04-12, 2, Comment 6, 2
2004-04-12, 2, Comment 7, 1

I have a table in which each of the system comments are defined.
Anything else appearing in the column is treated as a user comment.

Does anyone have any thoughts on how this could be achieved? The end
result will end up in an SQL Server 2000 stored procedure which will
be called from an ASP page to provide order taking stats.

Any help will be humbly and immensely appreciated!

Much warmth,

MurrayAssuming your tables look something like this:

CREATE TABLE Orders (custrep INTEGER NOT NULL, orderid INTEGER, orderdate
DATETIME NOT NULL, comment1 VARCHAR(2000) NULL, comment2 VARCHAR(2000) NULL,
comment3 VARCHAR(2000) NULL, comment4 VARCHAR(2000) NULL /*, PRIMARY KEY ?
*/)

CREATE TABLE SystemComments (comment VARCHAR(2000) PRIMARY KEY)

Try this:

SELECT O.orderdate, O.custrep, O.comment,
COUNT(S.comment) AS count_of_syscomments
FROM
(SELECT orderdate, custrep, comment1
FROM Orders
UNION ALL
SELECT orderdate, custrep, comment2
FROM Orders
UNION ALL
SELECT orderdate, custrep, comment3
FROM Orders
UNION ALL
SELECT orderdate, custrep, comment4
FROM Orders)
AS O (orderdate, custrep, comment)
LEFT JOIN SystemComments AS S
ON O.comment = S.comment
GROUP BY O.orderdate, O.custrep, O.comment

--
David Portas
SQL Server MVP
--|||On Fri, 14 May 2004 15:51:25 +0100, "David Portas"
<REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote:

>Assuming your tables look something like this:
>CREATE TABLE Orders (custrep INTEGER NOT NULL, orderid INTEGER, orderdate
>DATETIME NOT NULL, comment1 VARCHAR(2000) NULL, comment2 VARCHAR(2000) NULL,
>comment3 VARCHAR(2000) NULL, comment4 VARCHAR(2000) NULL /*, PRIMARY KEY ?
>*/)
>CREATE TABLE SystemComments (comment VARCHAR(2000) PRIMARY KEY)
>Try this:
>SELECT O.orderdate, O.custrep, O.comment,
> COUNT(S.comment) AS count_of_syscomments
> FROM
> (SELECT orderdate, custrep, comment1
> FROM Orders
> UNION ALL
> SELECT orderdate, custrep, comment2
> FROM Orders
> UNION ALL
> SELECT orderdate, custrep, comment3
> FROM Orders
> UNION ALL
> SELECT orderdate, custrep, comment4
> FROM Orders)
> AS O (orderdate, custrep, comment)
> LEFT JOIN SystemComments AS S
> ON O.comment = S.comment
> GROUP BY O.orderdate, O.custrep, O.comment

Hi David,

Thanks for the suggestion, unfortunately that's not how the table is
defined.

Sorry, I should have posted a pseudo create table statement as well.

It looks something like:

CREATE TABLE OrderComments (custrep INTEGER NOT NULL, orderid INTEGER,
orderdate DATETIME NOT NULL, comments VARCHAR(2000))

The create table statement you have for SystemComments is fine.

So, in the OrderComments table, the comments column might contain:

':Comment 1:Comment 2: Comment 8:Comment whatever'

So, each of the system and user generated comments for a particular
order are concatenated into a string and are put into a single column
(comments column) for that order.

Sorry for the confusion...

Much warmth,

Murray|||>So, in the OrderComments table, the comments column might contain:
>':Comment 1:Comment 2: Comment 8:Comment whatever'
>So, each of the system and user generated comments for a particular
>order are concatenated into a string and are put into a single column
>(comments column) for that order.
>Sorry for the confusion...
>Much warmth,
>Murray

Can I assume that these are free form and free for all type of
comments and not standardized ?

Is there some kind of unique seperator between comments ?

Been there, done this real recently and it wasn't pretty at all.

Randy
http://members.aol.com/rsmeiner|||You can try this:

SELECT O.orderdate, O.custrep, O.comments,
COALESCE(SUM((LEN(O.comments)-LEN(REPLACE(O.comments,S.comment,'')))
/LEN(S.comment)),0)
FROM OrderComments AS O
LEFT JOIN SystemComments AS S
ON O.comments LIKE '%'+S.comment+'%'
GROUP BY O.orderdate, O.custrep, O.comments

Don't expect great performance though!

--
David Portas
SQL Server MVP
--|||On 14 May 2004 15:20:02 GMT, rsmeiner@.aol.comcrap (RSMEINER) wrote:

[snip]

>>
>Can I assume that these are free form and free for all type of
>comments and not standardized ?
>Is there some kind of unique seperator between comments ?
>Been there, done this real recently and it wasn't pretty at all.

Hi Randy,

Pretty much, except that I have a reference table of the exact wording
of each of the system comments that might be found in the concatenated
value in the comments column.

The comments are delimited by a colon character, but I can't assume
that user comments, which get concatenated in the same field, will
always be lacking colon characters.

The only thing I can think to do is create a temp table in a stored
procedure and do multiple update...select statements to populate the
temp table, using the values in the predfined comments table.

I hear you that it isn't pretty.

Much warth,

Murray|||>Hi Randy,
>Pretty much, except that I have a reference table of the exact wording
>of each of the system comments that might be found in the concatenated
>value in the comments column.
>The comments are delimited by a colon character, but I can't assume
>that user comments, which get concatenated in the same field, will
>always be lacking colon characters.
>The only thing I can think to do is create a temp table in a stored
>procedure and do multiple update...select statements to populate the
>temp table, using the values in the predfined comments table.
>I hear you that it isn't pretty.
>Much warth,
>Murray

Since you have a table of the system comments, it makes it
much easier. I'm thinking on this.

How big are these tables ?

Randy
http://members.aol.com/rsmeiner|||Did you try my second solution?

--
David Portas
SQL Server MVP
--

Difficult Query. Is it possible?

Hi,

I am looking for a type of aggregate function for a string. Instead of finding a Max value or the average of a column, I would like to build one string value holding the aggregate.

Example:

Source data

RecordID PersonID Name Course Score

1 1 Fred Maths 70

2 1 Fred Science 78

3 2 Mary Maths 65

4 2 Mary Science 60

5 2 Mary History 85

I would like my query to return the following resultset:

Name Scores

Fred 70; 78

Mary 65; 60; 85

Hi R2 DJ,

In your ASP.NET Application, using DataGrid web server control and implementing ItemDataBound event.

Good Coding!

Javier Luna
http://guydotnetxmlwebservices.blogspot.com/

|||

You could use UDF's, but there are some limitations/dificulties.

For instance, the next sample is simple, but will only work for response sizes until varchar (max). You could do the same with text, but it would be a little bit more complicated:

create FUNCTION dbo.ConcatenateEmployeeCustomers

(

-- Add the parameters for the function here

@.iIDEmployee int

)

RETURNS varchar ( max )

AS

BEGIN

declare @.vcTotal as varchar (max )

set @.vcTotal = ''

select @.vcTotal = @.vcTotal + ISNULL ( CustomerID + ',' , '')

From orders

where EmployeeID = @.iIDEmployee

RETURN @.vcTotal

END

GO

select dbo.ConcatenateEmployeeCustomers ( EmployeeID ) , *

from employees

|||

In SQL Server 2005, you can do this using XML. For

your case, it would look something like this:

-- Adapted from an example posted by Erland Sommarskog

select

Name,

substring(IdList, 1, datalength(IdList)/2 - 1)

-- strip the last ',' from the list

from (

select distinct Name from YourTable

) as c -- or use a Names table if one exists

cross apply (

select

convert(nvarchar(30), PersonID) + ',' as [text()]

from YourTable as o

where o.PersonID = c.PersonID

order by o.RecordID

for xml path('')

) as Dummy(IdList)

Steve Kass

Drew University

www.stevekass.com

R2 DJ@.discussions.microsoft.com wrote:

> Hi,

>

> I am looking for a type of aggregate function for a string. Instead of

> finding a Max value or the average of a column, I would like to build

> one string value holding the aggregate.

>

> Example:

>

> Source data

>

> RecordID PersonID Name Course

> Score

>

> 1 1 Fred

> Maths 70

>

> 2 1 Fred

> Science 78

>

> 3 2 Mary

> Maths 65

>

> 4 2 Mary

> Science 60

>

> 5 2 Mary

> History 85

>

> I would like my query to return the following resultset:

>

> Name Scores

>

> Fred 70; 78

>

> Mary 65; 60; 85

>

>

Monday, March 19, 2012

differnce between a column that s a primary key and a column that s a "key/index with Isuni

Hi,

Please, What s the differnce between a column that s a primary key and a column that s a "key/index with Isunique=true"?

Thanks a lot.

EDIT

A Primary cannot be Null but Unique key can be Null. Check the links below for the documentation.

http://msdn2.microsoft.com/en-us/library/ms181043.aspx

http://msdn2.microsoft.com/en-us/library/ms191166.aspx

|||

Another difference is that if you use a UNIQUE constraint as a target for a foreign key reference you must explicitly reference the columns.

For instance, if you have a table "TableA" that has a primary key "TableA_PKCol", you can target that as a foreign key from table "TableB" with something like:

Code Snippet

Alter table TableB

add constraint FK_TableB__TableA

foreign key (TabkeA_PKCol)

references TableA

However, if you have a table "TableJ" that has a unique key "TableJ_UQCol", you must explicitly name that column to target this column as a foreign key target from "TableK" with something like:

Code Snippet

Alter table TableK

add constraint FK_TableK__TableJ

foreign key (TableJ_UQCol)

references TableJ (TableJ_UQCol)

Differential rows

I am using SSIS to replicate data from an AS400 mainframe to a SQL destination. I am using a lookup column to see if the primary key is duplicated and if not, it will INSERT the row. This is all working fine. What I need to know is can I also use the Lookup transformation to look for differential data and then UPDATE the row? The primary key of the table will never change, however the data might and I need the package to recognize that this is a modified row on the mainframe and that the same row on the SQL destination server needs to be updated.

Thanks for any useful information.

I believe that I found a solution to my own problem. It looks like I need to use the Slowly Changing Dimension transformation. So far in running the test data, this is exactly what I need.

Differential rows

I am using SSIS to replicate data from an AS400 mainframe to a SQL destination. I am using a lookup column to see if the primary key is duplicated and if not, it will INSERT the row. This is all working fine. What I need to know is can I also use the Lookup transformation to look for differential data and then UPDATE the row? The primary key of the table will never change, however the data might and I need the package to recognize that this is a modified row on the mainframe and that the same row on the SQL destination server needs to be updated.

Thanks for any useful information.

I believe that I found a solution to my own problem. It looks like I need to use the Slowly Changing Dimension transformation. So far in running the test data, this is exactly what I need.|||

Thank you so much for the answer to your own question! I've been using lookup and conditional split transformation to check if non-key columns have been modified. Writing an expression to compare all columns in a 40-column table has been making me go crazy. SCD does it all for you! In the literature I had in hand SCD is always used in the data warehouse context. Since I'm using IS for the data migration (only), I've never considered it as a transforamtion that could be of any use to me.

Wednesday, March 7, 2012

Different target links for link in the same report

I spent quite a bit of time trying work around this problem. Can
anypne help me with this?
I have several reports that I want to sort on the Column. When I sort
on the Column I call the same report and pass the parameters back to
and just change the Order by clause to the Column name. In the case
when I call the report I want it to appear in the same window. So I
use Target=_top.
On another field on the report I want the report to open in a new
window. Even if I set the URL to RC:Target=_blank it still opens in
the Parent window. If I user Target=_blank when calling the main
report, then all links open in new windows including when I sort on a
column.
Thanks
TomIn the current version of reporting services, all link targets for drill
through hyperlinks must have the same target value. It can only be set on
the parent report using rc:LinkTarget.
--
Bryan Keller
Developer Documentation
SQL Server Reporting Services
A friendly reminder that this posting is provided "AS IS" with no
warranties, and confers no rights.
"tmcgrath" <tmcgrath@.vhb.com> wrote in message
news:9e370943.0408161035.3d7471cc@.posting.google.com...
> I spent quite a bit of time trying work around this problem. Can
> anypne help me with this?
> I have several reports that I want to sort on the Column. When I sort
> on the Column I call the same report and pass the parameters back to
> and just change the Order by clause to the Column name. In the case
> when I call the report I want it to appear in the same window. So I
> use Target=_top.
> On another field on the report I want the report to open in a new
> window. Even if I set the URL to RC:Target=_blank it still opens in
> the Parent window. If I user Target=_blank when calling the main
> report, then all links open in new windows including when I sort on a
> column.
> Thanks
> Tom|||I've tried adding javascript into the Jump to URL field but whenever I click
the links nothing happens... nothing at all. My Java is on at least on my
local machine... i don't know about the actual report server, otherwise
certain parts of the web site I'm working on wouldn't work at all. Would it
be the settings on the report server or just something I seem to have missed
here?
"Nikola Tepper" wrote:
> Look at my post from 8/26:
> I think I have a solution. If you want a particular link to be opened in a
> new window, enter this into the "Jump to URL" field:
> javascript:if(window.open(yourPage.aspx','RsWindow','width=400,height=500,location=0,menubar=0,status=0,toolbar=0,scrollbars=1',true)){}
> Just play with the javascript, and you can direct the link into any frame
> you like, although you have to keep in mind security measures for iframes and
> frames
>
> "Bryan Keller [MSFT]" wrote:
> > In the current version of reporting services, all link targets for drill
> > through hyperlinks must have the same target value. It can only be set on
> > the parent report using rc:LinkTarget.
> >
> > --
> > Bryan Keller
> > Developer Documentation
> > SQL Server Reporting Services
> >
> > A friendly reminder that this posting is provided "AS IS" with no
> > warranties, and confers no rights.
> >
> >
> > "tmcgrath" <tmcgrath@.vhb.com> wrote in message
> > news:9e370943.0408161035.3d7471cc@.posting.google.com...
> > > I spent quite a bit of time trying work around this problem. Can
> > > anypne help me with this?
> > > I have several reports that I want to sort on the Column. When I sort
> > > on the Column I call the same report and pass the parameters back to
> > > and just change the Order by clause to the Column name. In the case
> > > when I call the report I want it to appear in the same window. So I
> > > use Target=_top.
> > > On another field on the report I want the report to open in a new
> > > window. Even if I set the URL to RC:Target=_blank it still opens in
> > > the Parent window. If I user Target=_blank when calling the main
> > > report, then all links open in new windows including when I sort on a
> > > column.
> > >
> > > Thanks
> > > Tom
> >
> >
> >

Different sums from table

Could someone explain to me, how I can get sum from row which I have values in 2 colums and I want the realtime sum to third column. Fourth colum is for item.

Also can someone tell me how to sum these third colums where the item is same so I have real time values for the item sum.

Thanks!

AD

Hi,

regardless that this makes no sense at all, this could be an example (as far as I understood your problem):

Select OrderId, Sum(Unitprice) + Sum (Quantity) AS ThirdColumn

from [Order Details]

Group by OrderId

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Different return formats

I have a table (call it table_a) that has a column with a datetime format.
1. When I run the following I get the following result:
select min(createdate) from table_a
RESULT: 2003-09-15 15:58:19.273
2. When I run the following I get the following result:
declare @.createdate datetime
select @.createdate = min(createdate) from table_a
print @.createdate
RESULT: Sep 15 2003 3:58PM
How can I get the variable @.createdate to hold the identical value returned in result #1?
--
Message posted via http://www.sqlmonster.comPRINT does not "return" a value it just prints to the output screen. Change
that to "SELECT @.Createdate" instead
"Robert Richards via SQLMonster.com" wrote:
> I have a table (call it table_a) that has a column with a datetime format.
> 1. When I run the following I get the following result:
> select min(createdate) from table_a
> RESULT: 2003-09-15 15:58:19.273
> 2. When I run the following I get the following result:
> declare @.createdate datetime
> select @.createdate = min(createdate) from table_a
> print @.createdate
> RESULT: Sep 15 2003 3:58PM
> How can I get the variable @.createdate to hold the identical value returned in result #1?
> --
> Message posted via http://www.sqlmonster.com
>|||PRINT performs an implict conversion to VARCHAR for its arguments. You can
use CONVERT to specify a format of something other than the default:
PRINT CONVERT(VARCHAR,@.createdate,121)
or you can just return the value as DATETIME, using SELECT, and format it
client-side.
--
David Portas
SQL Server MVP
--

Different return formats

I have a table (call it table_a) that has a column with a datetime format.
1. When I run the following I get the following result:
select min(createdate) from table_a
RESULT: 2003-09-15 15:58:19.273
2. When I run the following I get the following result:
declare @.createdate datetime
select @.createdate = min(createdate) from table_a
print @.createdate
RESULT: Sep 15 2003 3:58PM
How can I get the variable @.createdate to hold the identical value returned
in result #1?
Message posted via http://www.droptable.comPRINT does not "return" a value it just prints to the output screen. Change
that to "SELECT @.Createdate" instead
"Robert Richards via droptable.com" wrote:

> I have a table (call it table_a) that has a column with a datetime format.
> 1. When I run the following I get the following result:
> select min(createdate) from table_a
> RESULT: 2003-09-15 15:58:19.273
> 2. When I run the following I get the following result:
> declare @.createdate datetime
> select @.createdate = min(createdate) from table_a
> print @.createdate
> RESULT: Sep 15 2003 3:58PM
> How can I get the variable @.createdate to hold the identical value returne
d in result #1?
> --
> Message posted via http://www.droptable.com
>|||PRINT performs an implict conversion to VARCHAR for its arguments. You can
use CONVERT to specify a format of something other than the default:
PRINT CONVERT(VARCHAR,@.createdate,121)
or you can just return the value as DATETIME, using SELECT, and format it
client-side.
David Portas
SQL Server MVP
--

Different return formats

I have a table (call it table_a) that has a column with a datetime format.
1. When I run the following I get the following result:
select min(createdate) from table_a
RESULT: 2003-09-15 15:58:19.273
2. When I run the following I get the following result:
declare @.createdate datetime
select @.createdate = min(createdate) from table_a
print @.createdate
RESULT: Sep 15 2003 3:58PM
How can I get the variable @.createdate to hold the identical value returned in result #1?
Message posted via http://www.sqlmonster.com
PRINT does not "return" a value it just prints to the output screen. Change
that to "SELECT @.Createdate" instead
"Robert Richards via SQLMonster.com" wrote:

> I have a table (call it table_a) that has a column with a datetime format.
> 1. When I run the following I get the following result:
> select min(createdate) from table_a
> RESULT: 2003-09-15 15:58:19.273
> 2. When I run the following I get the following result:
> declare @.createdate datetime
> select @.createdate = min(createdate) from table_a
> print @.createdate
> RESULT: Sep 15 2003 3:58PM
> How can I get the variable @.createdate to hold the identical value returned in result #1?
> --
> Message posted via http://www.sqlmonster.com
>
|||PRINT performs an implict conversion to VARCHAR for its arguments. You can
use CONVERT to specify a format of something other than the default:
PRINT CONVERT(VARCHAR,@.createdate,121)
or you can just return the value as DATETIME, using SELECT, and format it
client-side.
David Portas
SQL Server MVP

Sunday, February 19, 2012

different colour background in matrix table results

Hi,

I have a matrix table with a subtotal column

I would like to make the background colour off this different to the rest of the matrix, how would i do this.

Also I would like to make some portions off the matrix results a different colour as well, how I can i acheive this

thanks

I have not used matrix recently. But dont you have the option of "Background Color" in properties. If you find one you should be able to wrte an expression with which you can control the color based on the value|||

it doesnt work !

I used under background colour in the results area with shift being a group

=IIF(Fields!shift = "Night",TRANSPARENT, BLACK)

It doesnt like the syntax

can someone else help

thanks

different colors for a matrix

Hi.
I have a matrix containing 3 row groups and 2 column groups and of course a detail area.
I want to show the detail area in different colors according to the row number.For example
1. row -->blue
2. row -->green
3. row -->blue

4. row -->green
5. row -->blue

6. row -->green
and so this goes....

I used the =IIF(RunningValue(FieldName, CountDistinct, "matrix1") Mod 2 , color1, color2)
for the detail's backgroundColor property
But it didn't work as I want.This caused a result like this:
1. row -->blue

2. row -->blue

3. row -->blue

4. row -->green

5. row -->blue

6. row -->green
.......
And I didn't understand how it works.
How could I do this.Which group name should I use in the formula?
Or do you have another idea for this problem?

Hi,

Chris Hayes blog has all the details you need:

http://blogs.msdn.com/chrishays/

Regards,

Sanjay

Friday, February 17, 2012

differenct between 2 select statments

I have 2 table (table1 & table2) where both contain documentpackageid column. In the first table I have a select:

SELECT documentpackageid FROM table1 WHERE xxx=94

The second table:

SELECT documentpackageid FROM table2 WHERE yyy<>10

Now I want the different between that 2 select statement. So that I have all documentpackageid from the first select - documentpakcageid from the second select

I have tried with:
SELECT documentpackageid FROM (SELECT documentpackageid FROM table1 WHERE xxx=94) AS foo WHERE foo.documentpackageoid !IN (SELECT documentpackageid FROM table2 WHERE yyy<>10);On Oracle the answer is:
SELECT documentpackageid FROM table1 WHERE xxx=94
MINUS
SELECT documentpackageid FROM table2 WHERE yyy<>10
Some DBMSs have "EXCEPT" instead of "MINUS".

If your DBMS has neither you can do this:

SELECT documentpackageid FROM table1 WHERE xxx=94
AND NOT EXISTS
( SELECT null FROM table2 WHERE yyy<>10
AND table2.documentpackageid = table2.documentpackageid)|||Hi, try this

select t1.documentpackageid -t2.documentpackageid from table1 t1,
table2 t2 where t1.xxx=94 and t2.yyy<>10

Madhivanan|||tony, mysql has neither EXCEPT nor MINUS

and versions prior to 4.1 don't even have subselects!!

here is another solution to this problem --select table1.documentpackageid
from table1
left outer
join table2
on table1.documentpackageid
= table2.documentpackageid
and table2.yyy <> 10
where table1.xxx = 94
and table2.documentpackageid is null

Differences in file sizes sys.database_files and sys.master_files

Hello,
We are seeing a differince in size column for the same files between
sys.database_files and sys.master_files. sys.master_files inidcates smaller
sizes so I think that rules out deferred drop operations. Any ideas? this
is for Tempdb files.
TIA,
All you need is /3GB. Don't worry about /PAE or AWE with 4GB of ram. You can
verify with just taskmgr. However, the RAM will not be commited until it is
needed. You can also look at the SQL memory manager:target server memory
perfmon counter.
/3GB is ok in this configuration most of the time but I would just use it
when it is needed. Sometimes it causes problem for the OS.
Jason Massie
www: http://statisticsio.com
rss: http://feeds.feedburner.com/statisticsio
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:94ECFB89-E022-4A97-988D-B1B992B3DE5D@.microsoft.com...
> Hello,
> We are seeing a differince in size column for the same files between
> sys.database_files and sys.master_files. sys.master_files inidcates
> smaller
> sizes so I think that rules out deferred drop operations. Any ideas?
> this
> is for Tempdb files.
> TIA,
|||Wow,
Super answer makes a lot of sense.
Thank you very much,
Joe
"Tibor Karaszi" wrote:

> Tempdb is special. Sys.master_files holds the size etc to make the tempdb size at startup (remember
> that tempdb is re-created each time you start SQL Server). Sys.database_files inside the database
> holds the actual values.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:94ECFB89-E022-4A97-988D-B1B992B3DE5D@.microsoft.com...
>
|||TIBOR ROCKS!! :-))
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:4A68FA71-9549-4B3F-8F3A-F09D548FF392@.microsoft.com...[vbcol=seagreen]
> Wow,
> Super answer makes a lot of sense.
> Thank you very much,
> Joe
> "Tibor Karaszi" wrote:

Differences in file sizes sys.database_files and sys.master_files

Hello,
We are seeing a differince in size column for the same files between
sys.database_files and sys.master_files. sys.master_files inidcates smaller
sizes so I think that rules out deferred drop operations. Any ideas? this
is for Tempdb files.
TIA,All you need is /3GB. Don't worry about /PAE or AWE with 4GB of ram. You can
verify with just taskmgr. However, the RAM will not be commited until it is
needed. You can also look at the SQL memory manager:target server memory
perfmon counter.
/3GB is ok in this configuration most of the time but I would just use it
when it is needed. Sometimes it causes problem for the OS.
Jason Massie
www: http://statisticsio.com
rss: http://feeds.feedburner.com/statisticsio
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:94ECFB89-E022-4A97-988D-B1B992B3DE5D@.microsoft.com...
> Hello,
> We are seeing a differince in size column for the same files between
> sys.database_files and sys.master_files. sys.master_files inidcates
> smaller
> sizes so I think that rules out deferred drop operations. Any ideas?
> this
> is for Tempdb files.
> TIA,|||Tempdb is special. Sys.master_files holds the size etc to make the tempdb size at startup (remember
that tempdb is re-created each time you start SQL Server). Sys.database_files inside the database
holds the actual values.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:94ECFB89-E022-4A97-988D-B1B992B3DE5D@.microsoft.com...
> Hello,
> We are seeing a differince in size column for the same files between
> sys.database_files and sys.master_files. sys.master_files inidcates smaller
> sizes so I think that rules out deferred drop operations. Any ideas? this
> is for Tempdb files.
> TIA,|||Wow,
Super answer makes a lot of sense.
Thank you very much,
Joe
"Tibor Karaszi" wrote:
> Tempdb is special. Sys.master_files holds the size etc to make the tempdb size at startup (remember
> that tempdb is re-created each time you start SQL Server). Sys.database_files inside the database
> holds the actual values.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:94ECFB89-E022-4A97-988D-B1B992B3DE5D@.microsoft.com...
> > Hello,
> > We are seeing a differince in size column for the same files between
> > sys.database_files and sys.master_files. sys.master_files inidcates smaller
> > sizes so I think that rules out deferred drop operations. Any ideas? this
> > is for Tempdb files.
> >
> > TIA,
>|||Glad you found it helpful. :-)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:4A68FA71-9549-4B3F-8F3A-F09D548FF392@.microsoft.com...
> Wow,
> Super answer makes a lot of sense.
> Thank you very much,
> Joe
> "Tibor Karaszi" wrote:
>> Tempdb is special. Sys.master_files holds the size etc to make the tempdb size at startup
>> (remember
>> that tempdb is re-created each time you start SQL Server). Sys.database_files inside the database
>> holds the actual values.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Joe" <Joe@.discussions.microsoft.com> wrote in message
>> news:94ECFB89-E022-4A97-988D-B1B992B3DE5D@.microsoft.com...
>> > Hello,
>> > We are seeing a differince in size column for the same files between
>> > sys.database_files and sys.master_files. sys.master_files inidcates smaller
>> > sizes so I think that rules out deferred drop operations. Any ideas? this
>> > is for Tempdb files.
>> >
>> > TIA,|||TIBOR ROCKS!! :-))
--
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:4A68FA71-9549-4B3F-8F3A-F09D548FF392@.microsoft.com...
> Wow,
> Super answer makes a lot of sense.
> Thank you very much,
> Joe
> "Tibor Karaszi" wrote:
>> Tempdb is special. Sys.master_files holds the size etc to make the tempdb
>> size at startup (remember
>> that tempdb is re-created each time you start SQL Server).
>> Sys.database_files inside the database
>> holds the actual values.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Joe" <Joe@.discussions.microsoft.com> wrote in message
>> news:94ECFB89-E022-4A97-988D-B1B992B3DE5D@.microsoft.com...
>> > Hello,
>> > We are seeing a differince in size column for the same files between
>> > sys.database_files and sys.master_files. sys.master_files inidcates
>> > smaller
>> > sizes so I think that rules out deferred drop operations. Any ideas?
>> > this
>> > is for Tempdb files.
>> >
>> > TIA,

Differences between two Columns

Has anyone computed a difference between two columns in a matrix agianst
the group by column?
Example
YEAR Diff
2003 2004
Company A 100 200 100
Company B 50 200 150
I posted this question earlier but I don't think I was clear about what
I was asking about. If anyone has any ideas please let me know. This
is a pretty common problem for our reporting efforts so a solution would
be greatly appreciated.
Thanks Ahead of Time
Steve
sfibich@.pfgc.comOne way to compute the difference between two columns is to write a function
(either embedded in the .rdl or as an assembly) and call the function from
the cell that is going to hold the return value.
Using your example and using an embedded function:
In the Tab=Layout of your design, click the menu item 'Report' then click
'Report
Properties'. On the resulting dialog box, click Tab=Code. Type in the
function:
Public Function ColumnDiff (YearAmt1 as integer, YearAmt2 as integer)
RETURN YearAmt2 - YearAmt1
End Function
Then in the Layout of your form: put the following expression in your 'Diff'
cell.
=Code.ColumnDiff(Fields!YearAmt1.Value, Fields!YearAmt2.Value)
Good Luck
Dawn|||Dawn wrote:
> One way to compute the difference between two columns is to write a function
> (either embedded in the .rdl or as an assembly) and call the function from
> the cell that is going to hold the return value.
> Using your example and using an embedded function:
> In the Tab=Layout of your design, click the menu item 'Report' then click
> 'Report
> Properties'. On the resulting dialog box, click Tab=Code. Type in the
> function:
> Public Function ColumnDiff (YearAmt1 as integer, YearAmt2 as integer)
> RETURN YearAmt2 - YearAmt1
> End Function
> Then in the Layout of your form: put the following expression in your 'Diff'
> cell.
> =Code.ColumnDiff(Fields!YearAmt1.Value, Fields!YearAmt2.Value)
> Good Luck
> Dawn
>
>
>
>
>
Thats not exactly what I'm looking for. My data is not structure in a
way that I have two columns of data already split on years, it is one
column depicting dollar values, another column depicting year.
Example Data Result Set:
Year Sales Dollars
2004 1000
2003 1020
2002 900
2001 50
2000 1000
What I would want is to put the data into a Matrix
Example:
Year 2004 2003 diff2004/2003 2002 diff
Dollar Value 1000 1020 -20 900 +30
I am wondering if anyone else is running into any year over year
comparison reports and how they are handling it. If anyone has any
suggestions please let me know.
Thanks