Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Sunday, March 25, 2012

Check inserted data in a SQL database

Hi im having problems as im new to ASP.NET C#

i have created a button to add details into a SQL database but i want to check the details before i insert the new values from the textboxes

can anyone help...... this is what i have to insert into the database......i just want some help to compare the user name eg... if user name exists a message will appear telling the user to change a different user name

Thanks


private void Button1_Click(object sender, System.EventArgs e)
{
string connectionString = "server=\'(local)\'; trusted_connection=true; database=\'tester\'";

//System.Data.IDbConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
System.Data.IDbConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
conn.Open();

string commandString = "INSERT INTO Users (UserName, Password) " + "Values(@.UserName, @.Password)";

//SqlCommand dbCommand = new SqlCommand (commandString, dbconn);

System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();

//System.Data.SqlClient.SqlCommand myCmd = new System.Data.SqlClient.SqlCommand(queryString, conn);

dbCommand.CommandText = commandString;

dbCommand.Connection = conn;

SqlParameter unParam = new SqlParameter ("@.UserName", SqlDbType.NVarChar, 60);
unParam.Value = txtUser.Text;
dbCommand.Parameters.Add(unParam);
SqlParameter paParam = new SqlParameter ("@.Password", SqlDbType.NVarChar, 60);
paParam.Value = txtPassword.Text;
dbCommand.Parameters.Add(paParam);

dbCommand.ExecuteNonQuery();

conn.Close();

Response.Redirect ("WebForm1.aspx");
}

create a stored procedure, pass in userName and password to it, then make the stored procedure check if user exists and return a value.
eg:

IF NOT EXISTS (SELECT user FROM some_table WHERE <A href="http://links.10026.com/?link=mailto:user=@.userName">user=@.userName</A>)
RETURN 0 /* user doesnt exist */
ELSE
RETURN 1

then

SqlParameter ret = new SqlParameter("@.retVal", SqlDbType.Int, 4);
ret.Direction = ParameterDirection.ReturnValue;

do an ExecuteScalar on your sql command and

int status = (int)sqlCmd.Parameters["@.retVal"].Value;
if (status == 0) { // user created }
else { // failed to create user; user exists }
sql

Thursday, March 22, 2012

check if schema exists

How can I tell if a schema already exists so that it doesn't have to be created?

If your schema should exist in the form of an .xsd file then you can use the system.io.file object as:

if system.io.file(path\name.xsd).exists then

the exists method will return a true if the file is present.

If this is not what you are looking for, where else might a "schema" exist that you would have to create one? In SQL? There too is the "Exists" keyword in t-SQL, you can, for instance create an SP that would look something like:

[based on the pubs demo db]

CREATE PROCEDURE dbo.MakeEmployeeTable

AS

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[employee]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[employee] (
[emp_id] [empid] NOT NULL ,
[fname] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[minit] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[lname] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[job_id] [smallint] NOT NULL ,
[job_lvl] [tinyint] NULL ,
[pub_id] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[hire_date] [datetime] NOT NULL
) ON [PRIMARY]

GO

This checks to see if a table is present and if it is not, adds it, with a given schema.

|||

I will take the other path and assume you meant relational schema :)

I use:

if schema_id('dog') is null
execute('create schema dog') --exec because 'CREATE SCHEMA' must be the first statement in a query batch.

|||Sorry. I should have mentioned that I am talking about schema in the database; not xml schema. Thanks for the help.|||

if exists(select * from sys.schemas where name = 'myschema')

begin

--ADD YOUR CODE HERE

end

else

begin

--ADD YOUR CODE HERE

--CREATE SCHEMA [myschema] AUTHORIZATION [dbo]

end

Check if record exists

Hello,

I created the following SQL script to check if a record exists:

IF (EXISTS (SELECT LevelName FROM dbo.by27_Levels WHERE LOWER(@.LevelName) = LOWER(LevelName)))
Return (1)
ELSE
Return (0)

And I also found in a web page another solution:
IF EXISTS(SELECT 1 FROM TABLENAME WHERE LevelName=@.LevelName)
SELECT 1
ELSE
SELECT 0

- Which approach should I use?
- Why "SELECT 1 FROM"?
- And when should I use SELECT or RETURN?

All I need is to know if the record exists ... nothing else.

I will use this procedure on an ASP.NET 2.0 / C# web site.
I am not sure if this important but anyway ...

Thank You,
Miguel

select 1 from table returns a value which is basically the same as selecting a column name when evaluating from the exists function. The difference is that 1 is a constant so the column name does not need to be looked up, and since you do not need the value of the column then select 1 can be used.

using return or select depends on what you are using to call the sql statement. If you use return then you need to look into the calls returns parameters. Using a select , you need to use a scalar or dataset return call. Most people use the select call because those calls are easier to handle but not necessarily more efficient

|||

In EXISTS you can use any of them but the result will be the same (it always look for first occurrence of value selected) I do not know about time of execution but I would prefer something like this

RETURN (CASE
when EXISTS (SELECT LevelName
FROM dbo.by27_Levels
WHERE LOWER(@.LevelName) = LOWER(LevelName))) then 1
else
0
end)

If it will be executed on SQL server and you server is Case insensitive you do not have to use LOWER and it will speed up a little.

Thanks

|||

ozkary:

If you use return then you need to look into the calls returns parameters.

What do you mean to look the calls returns parameters?

Can you point to some info about it?

Thanks,.

Miguel

|||

By default SQL Server is not case sensitive so the LOWER() is not needed.

If the LevelName is a unique key for the table I would avaoid using T-SQL and use a single generic SQL query:

SELECT COUNT(*) FROM dbo.by27_Levels WHERE @.LevelName = LevelName

RETURN ends the execution of the batch T-SQL and SELECT does not. Note any select results not stored in local variables will be output.

|||

Some stored procedures could have return parameters they are defined with OUTPUT

create procedure TEST

@.tcParam1 as varchar(100) = NULL,

@.tcOutputParam as varchar(100) = NULL OUTPUT

AS

BEGIN

...

SET @.tcOutputParam= 'result'

END

and if you call it

declare @.oparam as varchar(100)

exec test 'Test valuee', @.oparam OUTPUT

you can get output value from procedure

RETURN always is returned by stored procedure and you can get it like:but it only integer, output parameter can be almost any type

EXEC @.result = test 'Test valuee', @.oparam OUTPUT

Thanks

|||

yes, one usually uses parameters to call a stored procedure. Those parameters can have the following directions: INPUT, OUTPUT, RETURN.

To hadle a return value, one needs to add a return parameter to the call:

SqlCommand cmd = new SqlCommand("myProc", myConnection)

cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters..Add("ReturnValue", SqlDbType.Int).Direction = ParameterDirection.ReturnValue

add block to make the call

if using a reader make sure to close it before trying to read the return parameter

read the return parameter value

string value = cmd.Parameters.item["ReturnValue"].Value.Tostring();

for more info search on ParameterDirection.ReturnValue

I hope this helps.

Check if primary key exists

Hi!

I have created a formview which I among other things uses to insert new values into a database. What I want to check is if the primary key which is put into the form already exists in the db. If it is I want to get a message to my web page, if not the data can be inserted.

How can I do this?

And if the only way to control this is to create a stored procedure. How do I write such a proc?

If you attempt to insert a duplicate value into a PK field, an exception will be thrown. Why not set it to auto-increment and avoid all of this?

HTH,
Ryan

Monday, March 19, 2012

Check for a file before executing DTS

Thanks in advance for any help offered!

I am having a text file sent from another location on a daily basis. Suppposely @. 2:00 am. I created a DTS to bring the data into a local table (5:00AM). The data I am bringing in replaces the old data. So what happens in the DTS package is all data is dropped from the table and then the new data is inserted.

I then have another job run that runs later in the day before the next incoming data arrives (7:00PM). This job deletes the old text file so that it is not appended the next time the text file is sent to me.

The problem is that for the last two days, the server sending the text file did not send the files before my local jobs run (up to 9:00AM and 7:00AM). Thus my 7:00PM job has deleted the old text file. Then later my job that calls the DTS runs (5:00AM); it then drops all data and then tries to load new data that is not there because my 7:00PM job deleted the text file and the their 2:00AM has not delevered the new text file.

My question is; what is the best way to script a job that checks to see if the text file exist before dropping the existing table?

I know that the whole process could be handled better if both the supplier of the data and me the end user could be more flexible. The problem is that the sender is going to send the data in the manner (time and method) that requires the least amount of work for them. I just need to deal with it.
Thanks,
LeeWhat type of text file ? How are you processing it now in the your dts script ? What steps are currently being used in your dts script ?|||hi

I had the same problem with a daily based data import DTS I created. Here's the way I solved it:

Open your DTS in design view. Add an ActiveX component, written in vb script:

'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************

Function Main()
Set MyFile = CreateObject("Scripting.FileSystemObject")

If MyFile.FileExists(local_server_path) Then
Main = DTSTaskExecResult_Success
Else
Main = DTSTaskExecResult_Failure
End If
End Function
___________________________________________
___________________________________________

'local_server_path' is your file path on the server.

Use the 'onSuccess' event to start the rest of your DTS.

Hope it helps.

check file date and copy file

Hi,

I need to set up create a package so that I could check the date of the files posted in a folder, e.g. H:\source. If there is no file created later than one day exists, then continue to check again one hour later. If files do exists, then copy then to c:\dest and then upzip the files. Once this is done, sent an notification email to user@.mydomain.com.

Thanks,

Check out the FileWatcher task on SQLIS.com. It should help with identifying when the file appears. The rest of the tasks mentioned here are included with SSIS. You can use the File System task to copy files, and the Execute Process task to run a commandline utility to unzip them. The Send Mail task is used to send emails.|||

Hi,

I installed the program in the sqlis.com, but when I open the ssis business intelligent console, I can't find the filewatcher task in the toolbox. Can you tell me how to add this task in?

Thanks,

|||

There are instructions on SQLIS.com.

"The component is provided as an MSI file, however to complete the installation, you will have to add the task to the Visual Studio toolbox manually. Right-click the toolbox, and select Choose Items.... Select the SSIS Control Flow Items tab, and then check the File Watcher Task from the list."

Thursday, March 8, 2012

Check constraint - SQL problem

Hi,

I am new to database development and am writing a database as part of a
university course

I have created a table as below called CableWire - the table is created ok.

CREATE TABLE CableWire
(CableWireID CHAR(7),
BSstandard CHAR(16),
Colour VARCHAR(16),
Material VARCHAR(16),
MetresInStock INTEGER,
PRIMARY KEY (CableWireID));

However when I try to alter the table by adding a CHECK constraint:

ALTER TABLE CableWire
ADD CHECK (MetresInStock >= 0);

I get a pop-up box: "Line: 21
SQLSTATE = 37000
[Microsoft][ODBC dBase Driver] Syntax error in field definition, Continue?"

(line 21 equated to the 2nd of those 2 lines). The syntax seems perfectly
acceptable to me. Any help appreciated.

Regards,

MaryHello, Mary

The syntax is perfectly acceptable in Microsoft SQL Server 2000, but
are you using SQL Server or dBase ? The error message indicates that
the ODBC dBase driver is involved. If you want this to run on dBase,
perhaps you should try your question on another newsgroup.

Razvan|||Some minor commetns about the design and some questions.

1) Why is every non-key column NULL-able?

2) I don't know the wirte business, so who defines the cablewire_id
codes? I know the ISO stuff for machine screws, etc.

3) Likewise, what is the BS Standard. My first guess was British
Standards, since you spelled color wrong :)

4) Don' t you use Pantone or Land color numbers? Can you give me an
example of CHAR(16) color name? I assume that it is a name, not a
code, but since you did not follow ISO-11179 rules, I don't know.

CREATE TABLE CableWire
(cablewire_id CHAR(7) NOT NULL PRIMARY KEY,
bs_standard CHAR(16 NOT NULL),
colour_name VARCHAR(16) NOT NULL,
material_type VARCHAR(16) NOT NULL,
stock_level INTEGER DEFAULT 0 NOT NULL
CHECK (stock_level >= 0));

Otherwise, your syntax was fine.|||Hi Mary,
I have just created table and added check constraint using alter
statement without any error on SQL SERVER 2000. Could you send more
detail about environment where you encountered this error.
Ash
http://www.astragalaxy.com

Check Connection Exist

Lets say I have created an excel connection to an excel file.
During/Before runtime, I have deleted the file.

Is there any way for me to detect if the connection exists or not, and if the connection does not exist, skip a particular data flow process?Hi there,

You have a couple of options:
1. Use a script task to call out to System.IO.File.Exists to confirm the file exists. This will mean you'll have to get the file name from the connection string or use a variable that the connection manager's connection string uses itself.
2. Use a script task to call AcquireConnection on the connection to see if that succeeds.

Either way, put the result of the check into a variable and use that variable as a condition on the precedence constraint that goes from the script task to the data flow task.

Regards,
ash

Wednesday, March 7, 2012

Charts Not showing in some machines

Hello I am using crystatl reports 8.5 and Visual Basic 6.0

I have created a set up with all assemblies and installed in some machines and found that in some machines the Charts created using Crystal reports were showing but for some Blank Crystal reports appearing.

One of the machine where the chart now showing is XP PRofessional.

Need help urgently

Thanks in advanceWhere you ever able to resolve the problem? I am also having the same problem and have been looking for a week to try and resolve it and have tried all sort.

Please can you help?|||I have no luck with that.
So i have moved to vb.net from vb6.0 and with .net you have no such problems.

Sorry i cannot help you.

thanks and regards
vimal

Charts in subreports

Hello,
I´ve created a subreport to add it to my main report. When I open the main
report, the subreport is correct with all the parameters I´ve passed from
main to subreport.
The problem comes when I add a chart in the subreport. It shows an error
message like "Error: Subreport could not be shown" (or something like that).
Is it possible to add charts in subreports? Do I need special configuration
in the chart to be shown?
Thanks,
MónicaOn Aug 21, 6:28 am, "M=F3nica" <monica.d...@.augure.com> wrote:
> Hello,
> I=B4ve created a subreport to add it to my main report. When I open the m=ain
> report, the subreport is correct with all the parameters I=B4ve passed fr=om
> main to subreport.
> The problem comes when I add a chart in the subreport. It shows an error
> message like "Error: Subreport could not be shown" (or something like tha=t).
> Is it possible to add charts in subreports? Do I need special configurati=on
> in the chart to be shown?
> Thanks,
> M=F3nica
That shouldn't be a problem. It sounds like you are not correctly
providing the required parameter values/etc to the chart in the
subreport. Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||Make sure that in your subreport you define the same parameters and name
them the same thing as your parent report.
"Mónica" <monica.diaz@.augure.com> wrote in message
news:eyuybZ%234HHA.5360@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I´ve created a subreport to add it to my main report. When I open the main
> report, the subreport is correct with all the parameters I´ve passed from
> main to subreport.
> The problem comes when I add a chart in the subreport. It shows an error
> message like "Error: Subreport could not be shown" (or something like
> that).
> Is it possible to add charts in subreports? Do I need special
> configuration in the chart to be shown?
> Thanks,
> Mónica
>

Saturday, February 25, 2012

charts

I've created a stacked bar chart using reporting services. I'm
building the chart from 20 records that include amounts, years, ect.
The problem is whenever there are two amounts that are the same the
chart only shows one of the amounts. I tried to find out if there was
a property that was hiding duplicates with no luck.
thanksYou need to create a group for the chart that will identify the unique
records.
Andy Potter

Chart Y-axis Values Problem

I created a chart using some calculated fields, the calculations are working
correctly (I manually checked the math), but the Y axis values are way off.
The highest field value generated was 18,544 but the scale on the chart was
showing 500,000 with the bar reaching nearly to the top. I could understand
if the scale was just off and the bar stopped at the correct position, but
not only is the scale off, the bar doesn't correctly represent the value
either. Because this report will be used for several customers I can't
manually set a limit for the Y-axis. I turned off the labels for the Y-axis
so that I can use the chart, but I would prefer being able to see the labels.
I have installed SP1. Any help would be appreciated.
JoeHi, you can convert the scale of your chart in a expression in the RDL; try
it.
John Bocachica
Colombia
"JHoward" <JHoward@.discussions.microsoft.com> wrote in message
news:78D0BEDF-A212-4B07-9641-9A1615E6168F@.microsoft.com...
>I created a chart using some calculated fields, the calculations are
>working
> correctly (I manually checked the math), but the Y axis values are way
> off.
> The highest field value generated was 18,544 but the scale on the chart
> was
> showing 500,000 with the bar reaching nearly to the top. I could
> understand
> if the scale was just off and the bar stopped at the correct position, but
> not only is the scale off, the bar doesn't correctly represent the value
> either. Because this report will be used for several customers I can't
> manually set a limit for the Y-axis. I turned off the labels for the
> Y-axis
> so that I can use the chart, but I would prefer being able to see the
> labels.
> I have installed SP1. Any help would be appreciated.
> Joe|||Note: expression-based min/max/intervals will only be available on RS2005.
Joe, can you post a simplified report which runs e.g. based on Northwind
data and reproduces the issue?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"John Bocachica (Colombia)" <jbocachica@.gmail.com> wrote in message
news:e%23FQGGl%23EHA.1084@.tk2msftngp13.phx.gbl...
> Hi, you can convert the scale of your chart in a expression in the RDL;
try
> it.
> John Bocachica
> Colombia
> "JHoward" <JHoward@.discussions.microsoft.com> wrote in message
> news:78D0BEDF-A212-4B07-9641-9A1615E6168F@.microsoft.com...
> >I created a chart using some calculated fields, the calculations are
> >working
> > correctly (I manually checked the math), but the Y axis values are way
> > off.
> > The highest field value generated was 18,544 but the scale on the chart
> > was
> > showing 500,000 with the bar reaching nearly to the top. I could
> > understand
> > if the scale was just off and the bar stopped at the correct position,
but
> > not only is the scale off, the bar doesn't correctly represent the value
> > either. Because this report will be used for several customers I can't
> > manually set a limit for the Y-axis. I turned off the labels for the
> > Y-axis
> > so that I can use the chart, but I would prefer being able to see the
> > labels.
> > I have installed SP1. Any help would be appreciated.
> >
> > Joe
>

Friday, February 24, 2012

Chart Question...

Hi,
I'm trying to create a line graph/chart in reporting services. I have 2
stored procedures that outputs the count of 2 tables that created 2
datasets.
Both these procedures use a field called acctdates. I'm trying to use
the acctdates as the catagory field and the 2 counts in the data field. But
I keep receiving an error saying I can't use a field from another dataset
for the current dataset. Is there a way around this problem? or is there a
different way I should approach it?
Please help....
Thank you,
RickyYou may want to consider joining the two datasets inside a stored procedure.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ricky" <kmeas1@.gmail.com> wrote in message
news:Ow0xdjVNFHA.2372@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I'm trying to create a line graph/chart in reporting services. I have
> 2 stored procedures that outputs the count of 2 tables that created 2
> datasets.
> Both these procedures use a field called acctdates. I'm trying to
> use the acctdates as the catagory field and the 2 counts in the data
> field. But I keep receiving an error saying I can't use a field from
> another dataset for the current dataset. Is there a way around this
> problem? or is there a different way I should approach it?
> Please help....
>
> Thank you,
> Ricky
>

Chart legend has too much data - how to only show 1 legend

I have created a hybrid bar chart / with line. Basically uses the bars to
show sales for each geographic region. A single line is plotted showing the
sales goal to be reached. The x axis is "Region" The y axis value 1 is total
sales $. I added y value 2 to show the sales goal $ and the legend
automatically got populated with series labels. I only want the x axis
labels to be in the legend.
How can I fix this?NP,
This is not a direct answer to your question, but I got tired of the report
legend and what seemed the lack of configuration and used a nice trick from
the Technical Article: Get More Out of SQL Server Reporting Services Charts
(http://msdn2.microsoft.com/en-us/library/aa964128.aspx) to create my own
legend. The document is excellent, five stars.
If you use the Custom Chart Color Palettes and Legends section from the doc
you will see what I mean. You are able to create your own legend and use what
you want and remove what you don't.
Hope this helps.
Reeves
"NP" wrote:
> I have created a hybrid bar chart / with line. Basically uses the bars to
> show sales for each geographic region. A single line is plotted showing the
> sales goal to be reached. The x axis is "Region" The y axis value 1 is total
> sales $. I added y value 2 to show the sales goal $ and the legend
> automatically got populated with series labels. I only want the x axis
> labels to be in the legend.
> How can I fix this?

Chart Labels at an angle?

Hi,

I have created a report with bar chart but the labels are too long and often go into next line. Is there any way to specify text orientation for labels of a bar chart? I would like to show the chart labels at an angle. Is it possible?

Any help will be appreciated!

This depends on which labels you are referring to. If you are referring to data point labels, then yes, it is possible to specifiy an angle. However, if you are referring to the labels on one of the axes, then no, it is not possible at this time to specify an angle. These labels are positioned automatically. The ability to manually set the angle for axis labels is a potential new feature for the next version of Reporting Services.

To Set the Angle for Data Point Labels:
In the Report Designer, there is a section on the Chart Value properties dialog that allows you to specify an angle for data point labels. This is located on the Point Labels tab of this dialog, which can be reached by creating or editing a Chart Value on the Data tab of the Chart properties dialog.

Chart i blurring in IE

Hi,
I created a chart through the reporting services. The chart is very clear if
I preview it throguh the Report Designer. However, it is very blurring when I
view the report through the Report Manager or Internet Explorer.
Any ideas about this problem?
Thanks,
DavidAre just the fonts in the chart "blurring" when shown in IE? If that is the
case, then most likely, the report server machine has "ClearType" turned on
(Control Panel - Display - Appearance - Effects). Does turning ClearType off
improve it?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"David" <wei.liu@.powerinfonet.com> wrote in message
news:CB3F80F8-1630-4C36-8C67-1745E888B51A@.microsoft.com...
> Hi,
> I created a chart through the reporting services. The chart is very clear
> if
> I preview it throguh the Report Designer. However, it is very blurring
> when I
> view the report through the Report Manager or Internet Explorer.
> Any ideas about this problem?
> Thanks,
> David|||Hi, Robert:
Thank you very much for your information. I tried ClearType and it does not
work in my case. I am using URL to access the report. If I set the
HTMLFragment to true, I get a much better quality chart report.
I have another question. Right now I have multiple reports in one HTML page.
Therefore, each report has its own horizontal frame. Is it possible to set
all reports have one horizontal frame?
Thank you for your kind help,
Best regards,
Favid
"Robert Bruckner [MSFT]" wrote:
> Are just the fonts in the chart "blurring" when shown in IE? If that is the
> case, then most likely, the report server machine has "ClearType" turned on
> (Control Panel - Display - Appearance - Effects). Does turning ClearType off
> improve it?
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "David" <wei.liu@.powerinfonet.com> wrote in message
> news:CB3F80F8-1630-4C36-8C67-1745E888B51A@.microsoft.com...
> > Hi,
> >
> > I created a chart through the reporting services. The chart is very clear
> > if
> > I preview it throguh the Report Designer. However, it is very blurring
> > when I
> > view the report through the Report Manager or Internet Explorer.
> >
> > Any ideas about this problem?
> >
> > Thanks,
> >
> > David
>
>

Sunday, February 19, 2012

Chart Axis

I have created a bar chart with percentages as the variables. The numbers on
the chart are correct, but the scale is incorrect. The scale adjusts to 100%
for all fields.
Anyone else encountered this problem?
--
TDWhen using percentages (e.g. format code P on the Y-axis), you can either
auto-scale the axis or you can specify an explicit min/max value. If you
specify an explicit max value (e.g. 120%), you have to specify it as 1.2
rather than 120
For percentages, 1 means 100%.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"TDahlin" <TDahlin@.discussions.microsoft.com> wrote in message
news:D87A2D0A-D607-4483-A3B4-484A07B2C5AC@.microsoft.com...
>I have created a bar chart with percentages as the variables. The numbers
>on
> the chart are correct, but the scale is incorrect. The scale adjusts to
> 100%
> for all fields.
> Anyone else encountered this problem?
> --
> TD

Thursday, February 16, 2012

charset

I've created a table with an Nvarchar field in SQL server.
When I insert a chinese word using Query Analyser, I can use N'chinese word
for updating.
Howeve I can update the chinese word from web page.
Can anyone help me?
ThanksHoweve I can't update the chinese word from web page
"Win" <aaa@.aaa.com> wrote in message
news:udPajVzPFHA.1236@.TK2MSFTNGP14.phx.gbl...
> I've created a table with an Nvarchar field in SQL server.
> When I insert a chinese word using Query Analyser, I can use N'chinese
word
> for updating.
> Howeve I can update the chinese word from web page.
> Can anyone help me?
> Thanks
>

Sunday, February 12, 2012

char vs. varchar

Greetings,

I have a question. I work on some SQL2k/ASP.NET apps at work. My
predacessor, who created the databases/tables seemed to have liked to
use 'char' for all text fields. Is there a reason why he would have
done this over using varchar? It's a minor annoyance to always have to
RTRIM data and it makes directly making changes to the database more
annoying (with all the pointless trailing spaces)?

I usually use char for fixed string lengths, like state abbreviations
or something, and varchar for strings of unknown length.

Is it a performance issue? Our database doesn't do much traffic, for
the most part.It's not a performance issue unless you're using varchar(1) and the
overhead that incurs and have millions of records and higher traffic
than you probably have.

As a matter of fact, for larger char() fields, they can be slower than
varchar(), because it has to physically store more data pages than if
you used varchar(). If there are more data pages for the same number
of records, things get slower.

Make life easy on yourself and use varchar(). Don't use varchar(1)
though. I have seen people use it.|||The difference between char and varchar are in both storage and performance:

1. Storage wise: char columns have fixed length. If the user supplied value
for the column is less than the fixed length defined in the schema, the
column is padded with 0 at end to make the total length fixed. varchar
doesn't have a fixed length thus no padding is needed. But as the result
varchar columns have to store the size of the data together with the column
data, which takes an extra 2 bytes per varchar column.

2. Performance wise locating char is a little faster than varchar. Since
char columns have fixed length, they are stored in fixed location in a row.
This means locating a char column can directly jump to the fixed location in
a row to read. For varchar column since the size of the data is variable,
they can't be stored in fixed location in a row and rather there is soem
kind of lookup table in the row format to store the location of each varchar
column. This means locating a varchar column has to lookup the location of
the column in the lookup table stored in the row first before jumping to the
location to read. Referencing the lokup table introduces some perofrmance
overhead, especially ifthe lookup table reference causes cache line miss.

In summary, it is a matter of trade-off between padding+faster locate and
2-bytes-overhead-per-column+slower locate when choosing char v.s. varchar.

--
Gang He
Software Design Engineer
Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.
<dmhendricks@.despammed.com> wrote in message
news:1105723409.312275.186390@.f14g2000cwb.googlegr oups.com...
> Greetings,
> I have a question. I work on some SQL2k/ASP.NET apps at work. My
> predacessor, who created the databases/tables seemed to have liked to
> use 'char' for all text fields. Is there a reason why he would have
> done this over using varchar? It's a minor annoyance to always have to
> RTRIM data and it makes directly making changes to the database more
> annoying (with all the pointless trailing spaces)?
> I usually use char for fixed string lengths, like state abbreviations
> or something, and varchar for strings of unknown length.
> Is it a performance issue? Our database doesn't do much traffic, for
> the most part.|||You would never see a practical performance advantage in using char
over varchar, unless you had an extremely high transaction application.
The varchar offset lookup is optimized in-memory. The real bottleneck
is disk I/O, not a few extra CPU cycles from looking up varchar
offsets.

If I have an app that uses a char(80), versus an app that uses a
varchar(80), with an average width of data of 40, the char(80) data is
going to use approximately twice as many data pages to store the data.
That means twice as much disk I/O to read the table, which is where the
real bottleneck is.

I don't believe there is any tradeoff here.|||Gary, see inline

Gary wrote:
> You would never see a practical performance advantage in using char
> over varchar, unless you had an extremely high transaction application.
> The varchar offset lookup is optimized in-memory.

I agree that you won't see any performance degradation here.

> The real bottleneck is disk I/O, not a few extra CPU cycles from looking up varchar
> offsets.

Again, I agree

> If I have an app that uses a char(80), versus an app that uses a
> varchar(80), with an average width of data of 40, the char(80) data is
> going to use approximately twice as many data pages to store the data.
> That means twice as much disk I/O to read the table, which is where the
> real bottleneck is.

This is only true in a perfect world scenario. If there is insufficient
free space to accomodate changes in the varchar data, then change
changes in the varchar(80) data will lead to fragmentation. Changes in
the char(80) data will not lead to fragementation, because any
replacement can be done in-place (assuming columns not part of a
clustered index).

So depending on the fill-factor, number of data changes, etc.
fragmentation will be a little or much greater for varchar compared to
char. This fragmentation is (as you probably know) especially expensive,
because it needs random I/O which is slower than sequential I/O.

I you reindex regularly, and have a sufficient fill factor, then
varchar(80) should always perform better if the average length is only
40.

> I don't believe there is any tradeoff here.

Personally, I don't see a good reason why one would ever choose a
varchar over char when the maximum size is 4 characters or less. For
sizes over 10 characters I tend to choose varchar almost automatically.
For anything between 4 and 10 I really think about the situation before
deciding char or varchar.

Gert-Jan|||Gert-Jan -

I totally agree with you. I simplified the situation quite a bit, but
with all other things being equal, yours is a good "guesstimate".

I ran a test "perfect world" scenario of char(80) vs. varchar(80) (40
char avg len), and both the CPU time and disk I/O were about 40% higher
with the char(80) scenario with 10000 records.

Gary

Friday, February 10, 2012

Changing variable scope in package templates?

Is there any way to change variable scope while using package templates?

I have created a package template that has several variables, a "typical" control flow and data flow. My goal was to try and use this as a starting point to create other packages within the same project and edit as required in the new package. I couldn't find any way (yet) to change scope of variables...these still show as belonging to the scope of package used to create the template.

Appreciate any help...thanks.

You can't change the scope of variables unfortunately.

Just drop it and recreate it instead.

-Jamie

|||

After some experimentation I was able to achieve this by directly editing the package file (.dtsx) and associated configuration (.dtsConfig) file. It is great that these are XML files. The basic steps follow:

Copy "template" .dtsx and .dtsConfig files and rename as desired.

In new files replace all "template" package name with new package name.

Open new package in SSIS - the variables are now in the new package scope.

Make sure you generate a new GUID for the new package within SSIS.

|||

I had created several variables in the wrong scope ..data flow scope that I needed to reference in the control flow.

Change variable scope -

1. created a dummy variable that I could Ctrl F easily in the control flow

2. under view -> Code

3. within the XML, Ctrl F the variable that was in the wrong scope and cut (ctrl X) the XML out of the dataflow scope.

4. paste the xml into the package scope directly underneath my dummy variable.

5. save XML (I saved as a different name to prevent corruption).