Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Friday, March 30, 2012

Numeric value only for a character field

Hi
I have a character field (char ot varchar) that I want to force only to
contain numeric characters.
Can that be done by way of defining a constraint on the field ?
or by any other way in the field/table definition ?
What id the syntax ?
Anyone have examples ?

Thanks

David GreenbergOn Thu, 02 Aug 2007 10:05:40 +0200, David Greenberg wrote:

Quote:

Originally Posted by

>Hi
>I have a character field (char ot varchar) that I want to force only to
>contain numeric characters.
>Can that be done by way of defining a constraint on the field ?
>or by any other way in the field/table definition ?
>What id the syntax ?
>Anyone have examples ?


Hi David,

The obvious solution is to declare the column with one of the numeric
data types instead of char or varchar.

But if you insist on using character columns for numeric data, you can
add a CHECK constraint:

CREATE TABLE Example
(SomeCol char(9) CHECK (SomeCol NOT LIKE '%[^0-9]%'));

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

Wednesday, March 21, 2012

number of locks

Hi!
I did not change parameter locks after installation, so it
has following values:
nameminimummaximumconfig_valuerun_value
locks5000214748364700
So far did not experience any problem, Do I have to change
this in order to prevent problem with locks? Which number
of locks is available at this moment?
You're probably fine with the default numbers. Most people never change
them. Is there a particular problem you're worried about or think you may be
having?
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"mirce" <anonymous@.discussions.microsoft.com> wrote in message
news:2f1001c4a231$27bf6b50$a601280a@.phx.gbl...
> Hi!
> I did not change parameter locks after installation, so it
> has following values:
> name minimum maximum config_value run_value
> locks 5000 2147483647 0 0
> So far did not experience any problem, Do I have to change
> this in order to prevent problem with locks? Which number
> of locks is available at this moment?
|||No I did not have any problem. What is current value of
available locks?

>--Original Message--
>You're probably fine with the default numbers. Most
people never change
>them. Is there a particular problem you're worried about
or think you may be
>having?
>--
>Brian Moran
>Principal Mentor
>Solid Quality Learning
>SQL Server MVP
>http://www.solidqualitylearning.com
>
>"mirce" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:2f1001c4a231$27bf6b50$a601280a@.phx.gbl...
it[vbcol=seagreen]
change[vbcol=seagreen]
number
>
>.
>

Number of Dataset per Report

Hi

I am creating this report which requires 50 datasets to be created.

I was just wondering Is there any recommended number of dataset per report? Or Number of controls per report?

I really dont want to create this big number of dataset per report but sometimes its difficult to explain client.

Regards

Amit

There is not hard limit on the number of dataset or controls per report. It is possible that you might see problems if you have very complex report or if the dataset is very large at runtime depending on what kind of hardware you have (e.g. memory) though.|||

Thanks Fang for your reply.

I think I am not using much complex report. They are all simple queries but have to create separated dataset for each query.

I will make sure that client use the best hardware configuration.

Best Regards

Amit

Monday, March 19, 2012

Number formatting in a SQL select statement

Hi

I'm trying to convert and format integer values in a SQL Server select statement to a string
representation of the number formated with ,'s (1000000 becomes 1,000,000 for example).

I've been looking at CAST and CONVERT and think the answers there somewhere. I just don't
seem to be able to work it out.

Anyone out there able to help me please?

Thanks,
Keith.

My suggestion would be to do this on the front end rather than the back end.
In any case, I think you will need to CAST your column as a money data type, and then CONVERT it using style 1, like this:
SELECT
CONVERT(varchar(20),CAST(myColumn AS money) ,1)
This will unfortuately also return the 2 digits after the decimal point. So my next step would be to strip them out.
This seems very messy, though. Hopefully someone else will have a better idea.

|||Yeah, that is messy.
<soapbox>
The first question I have is why isn't this being done in yourpresentation layer? SQL's strong suit is selecting data, not formattingit. Your ASP.NET environment already has tools that make this mucheasier than anything that we can come up with in SQL.
</soapbox>
Even messier would be this code sample, which is a function and/orstored procedure that accomplish what you are looking for. I've neverused it, but it looks right to me.
Jason
Update: Forgot to link - http://www.issociate.de/board/post/176502/How_do_I_format_an_integer.html
|||

Definitely a front-end issue. I've had to use SQL to format results when using SQLMail and it's a nightmare. Possible using combinations of cast, convert, charindex, substring, etc., but a nightmare. Use the front-end.

|||

Try this url it is using Strings and Formatting in the Framework Class library to do custom formatting. Hope this helps.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomnumericformatstringsoutputexample.asp

Kind regards,

Gift Peddie

number formats (again!)

Hi

I'm having a problem with displaying my reports through my application at runtime. One of the formula fields on the report contains the id of the record I'm displaying and if the record's Verified field = True, it also shows a string. The formula is this:

If {?PubNoVer} = "Yes" then
if {View_TM_Get_BookID_BY_Surname.Verified} = True Then
{View_TM_Get_BookID_BY_Surname.BookID} & " Verified"
Else
{View_TM_Get_BookID_BY_Surname.BookID} & " "
Else
" "

In the report preview window, this all looks fine but running it through my application made any four digit id look wrong because it added a thousand separator and decimal places e.g. 1,512.00

In a previous post on another forum, a user very kindly showed me that using ToText on the ID field would get rid of the decimal places, so that's fine, but I still have the thousand separator and can't get rid of it!

Does anyone have any ideas?just format the field


right click on field, select format field, go to number that and select the format u want to display in|||just format the field


right click on field, select format field, go to number that and select the format u want to display in

Yeah, I did that but it only shows the correct format in the preview window, when running the report through the application, it shows the thousand separator and the decimal places even though i'd specified for that not to happen!

OK, I've found half an answer on another site. To get rid of both the decimal places and the thousands separators you use:

ToText({fieldname},0,"")

This works but because I'm also grouping on the id field, the ids still show with a thousands separator on the group tree at the side of the report! Anybody know how to format that?!|||You could create a formula like:

right('0000000000' & totext({fieldname}, 0, ""), 10)

and then group on that formula instead of the fieldname.
Trouble is you get a load of leading zeros in front of the number in the group tree.
You could limit this by finding the maximum length of the field with a whilereadingrecords formula and changing the formula to
right(replicatestring('0', {@.maxlen}) & totext({fieldname}, 0, ""), {@.maxlen})

You could use a space instead of a zero, but the numbers in the group tree won't line up, although they will still be in numeric order.

If anyone knows another way (apart from setting the PC's local settings) I'd like to know...|||You could create a formula like:

right('0000000000' & totext({fieldname}, 0, ""), 10)

and then group on that formula instead of the fieldname.
Trouble is you get a load of leading zeros in front of the number in the group tree.

Thanks JaganEllis. Instead of the formula you suggested, I used ToText({fieldname}, 0, "") and grouped on it and this worked perfectly!|||I can see how that helps with the format of the group tree data, but what about the group ordering? Unless all your number have the same number of digits, the order will be messed up (if important to you).
e.g. 300 will be after 2000 because the string '3' is > the string '2'|||I can see how that helps with the format of the group tree data, but what about the group ordering? Unless all your number have the same number of digits, the order will be messed up (if important to you).
e.g. 300 will be after 2000 because the string '3' is > the string '2'

Ah right... I see what you mean! I've used spaces instead of zeros. Thanks!

number formats

Hi

I'm using Crystal Reports for Visual Studio 2005. I'm having problems with displaying numbers in the correct format.

I've gone into Design > Default Settings menu and set the format of number fields to no decimal place (i.e. 1 instead of 1.0) and taken out the thousand separator. But this doesn't seem to have made a difference.

On one report, the numbers show ok (e.g. 54) on the report preview but when I run it through my application, the numbers are showing with decimal places (e.g. 54.00).

On another report, the ids of the records shown in the report appear in the group tree and have thousand separators on them when run through my application. As with the other report, they appear correctly in the report preview!

How can I make the format show correctly when running the report through my application?

ThanksFor anyone that's interested, I got the answer elsewhere. the formula to use is ToText({fieldname},0,"")

Wednesday, March 7, 2012

null values in sql server

Hi

I am importing an excel spreadsheet into tables in a sql server database using dts. I have one row of information filled out in the excel spreadsheet, but when the dts runs, it imports the information plus 5 extra rows filled with nulls ino the table.

Does anyone know how to fix this?

ThanksDid those rows have values in them previously but were erased? Here is an idea (I don't know if it will work). Try creating a new Excel Spreadsheet and cut-and-paste your valid rows from your original spreadsheet into the new spreadsheet, save it and try your DTS package again.|||Open the excel and remove the last 5 rows from the bottom which has null value.
I would rather prefer to save the excel sheet as .TXT file and then import the txt file.
Excel always seem to do something funny with the DTS.

Saturday, February 25, 2012

Null value problem

Hi
I sent the following query
'Update TableA SET F1 = F1 + F2'
and where the value of F2 was Null then the value of F1 became Null even
where the original value of F1 was NOT Null
Is that the way it suppose to work?
Thank you,
Samuel
Samuel Shulman wrote:

>Hi
>I sent the following query
>'Update TableA SET F1 = F1 + F2'
> and where the value of F2 was Null then the value of F1 became Null even
>where the original value of F1 was NOT Null
>Is that the way it suppose to work?
>
>
Yes.
If you want to leave the value of F1 unchanged (assuming
F1 and F2 are numeric types), try
UPDATE TableA SET F1 = F1 + COALESCE(F2,0)
or
UPDATE TableA SET F1 = F1 + F2
WHERE F2 IS NOT NULL
Steve Kass
Drew University

>Thank you,
>Samuel
>
>|||Yes NULL + any other value = NULL (depending on CONCAT_NULL_YIELDS_NULL
setting of course)
select NULL + 'ABC' -- this will return NULL
do this instead for strings
Update TableA SET F1 = coalesce(F1,'') + coalesce(F2,'') or
for numeric values
Update TableA SET F1 = coalesce(F1,0') + coalesce(F2,0)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
Samuel Shulman wrote:
> Hi
> I sent the following query
> 'Update TableA SET F1 = F1 + F2'
> and where the value of F2 was Null then the value of F1 became Null even
> where the original value of F1 was NOT Null
> Is that the way it suppose to work?
> Thank you,
> Samuel|||What data types are using? Are you trying to concatenate or ADD
Post a "real " example.
If you were trying to add, then NULL + 1 , will result in NULL , you could
get around the problem by using the ISNULL function.
Therefore you could do something like 'Update TableA SET F1 = ISNULL(F1,0) +
ISNULL(F2,0)'
--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"Samuel Shulman" <samuel.shulman@.ntlworld.com> wrote in message
news:OaAFwvKiGHA.4080@.TK2MSFTNGP03.phx.gbl...
> Hi
> I sent the following query
> 'Update TableA SET F1 = F1 + F2'
> and where the value of F2 was Null then the value of F1 became Null even
> where the original value of F1 was NOT Null
> Is that the way it suppose to work?
> Thank you,
> Samuel
>|||Samuel Shulman (samuel.shulman@.ntlworld.com) writes:
> I sent the following query
> 'Update TableA SET F1 = F1 + F2'
> and where the value of F2 was Null then the value of F1 became Null even
> where the original value of F1 was NOT Null
> Is that the way it suppose to work?
Yes. NULL is an unknown value, and it doesn't become less unkonown because
you add it with a known value.
If you know that in the specific context that you are working in that a
NULL is the same thing as 0, you can say
UPDATE TableA SET F1 = F1 + coalesce(F2, 0)
The function coalesce() takes a list of expressions as argument, and returns
the the first non-NULL value in the list, or NULL if all are NULL.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Yes coalesce() is the way to go.
Best Regards
Vadivel
http://vadivel.blogspot.com
"Samuel Shulman" wrote:

> Hi
> I sent the following query
> 'Update TableA SET F1 = F1 + F2'
> and where the value of F2 was Null then the value of F1 became Null even
> where the original value of F1 was NOT Null
> Is that the way it suppose to work?
> Thank you,
> Samuel
>
>|||Just in addition to what others have noted...
If NULL really means 0 or '', then make your column not null and define the
appropriate default.
NULLs have a behavior all their own, and you either have to prevent the NULL
values up front, or code for them after the fact.
"Samuel Shulman" <samuel.shulman@.ntlworld.com> wrote in message
news:OaAFwvKiGHA.4080@.TK2MSFTNGP03.phx.gbl...
> Hi
> I sent the following query
> 'Update TableA SET F1 = F1 + F2'
> and where the value of F2 was Null then the value of F1 became Null even
> where the original value of F1 was NOT Null
> Is that the way it suppose to work?
> Thank you,
> Samuel
>