Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Friday, March 30, 2012

how to control the table's column number

Hi,

When I add the table into the report, the default column number is 3. Let's say I need 10 columns on the report, besides right click on the last column and click on "add column right" to add the other 7 columns, is there any easy way?

Thanks.

Sorry, there is no other way of doing this. You have to add additional columns through the popup menu.

-- Robert

sql

how to control the number of row?

i want to contorl the output number of row with a certain number when select data from table that not exceed the number with my setting.

For example,if the result is exceed the 500 rows, then i just require 200 rows, that what is the command of this function?

Thanks for any help...

You can try something like:

SELECT top 500
...
from TableName

another more archaic form is to execute

SET ROWCOUNT 500

However, this will also limit the number of records update or inserted, deleted etc. Turn off the limit by:

SET ROWCOUNT 0

The TOP option is in general the better option. Look the two up in books online.

sql

How to control number precision?

Hi all,
There is a table like this:
item quantity
-
A 1
B 3
C 7
D 6
Now I want to get a table like this:
item Percent
-
A 1/17
B 3/17
C 7/17
D 6/17
For script:
select item,
quantity/sum(quantity)
from table
but the number has a very long precision, like 0.0588235456456, I only want to keep two number after the point as like 0.06,what should I do?
Thanks!

Coeus:

Maybe something like:

select convert (numeric (9,2), 0.0588235456456)

|||

Thanks for help. :)

I also can use round(variable, 2).

Wednesday, March 21, 2012

how to confine a field to be number characters only?

i have a field which is CHAR(20), and it is allowed to only containe number chars.

is there any collation_name can help ? or how can i set the check clause ?

Here is a couple of ways that I would do it (no promises, and there could be better ways :)

DECLARE @.test char(20)
SELECT @.test = '12345678901234567890'

--All 20 characters are numbers
SELECT CASE WHEN @.test LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' THEN 'Yes' ELSE 'No' END

--allows trailing blanks (that is what the replace to an ampersand does.)
SELECT CASE WHEN len(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(rtrim(@.test),' ','@.'),'0',''),'1',''),'2',''),'3',''),'4',''),'5',''),'6',''),'7',''),'8',''),'9','')) = 0 then 1 else 0 end

|||

You can also add a check constraint ot the table

CREATE TABLE TestNumbersOnly (SomeColumn char(20), CONSTRAINT NumericOnlyPlease CHECK (SomeColumn NOT LIKE '%[a-z]%' AND ISNUMERIC(SomeColumn) = 1))

Let's test
--Good
INSERT TestNumbersOnly VALUES ('12345678901234567890')
--Good
INSERT TestNumbersOnly VALUES ('1234567890123456789')

--Bad
INSERT TestNumbersOnly VALUES ('1234567890123456789A')
--Bad
INSERT TestNumbersOnly VALUES ('123(4567890123456789')
--Bad
INSERT TestNumbersOnly VALUES ('123-4567890123456789')

Denis the SQL Menace

http://sqlservercode.blogspot.com/

|||Why don't you use one of the numeric or integer data types then for the column? It is much cleaner, easier and efficient if you use the correct data type for the data. Using character data types has several issues in that you need to enforce your own constraints, the query optimizer doesn't know that the values are only numeric for example, and if you need to perform arithmetic operations then you need to cast the value explicitly & so on. Is there any business reason to store numeric values in character column? This is a problem with the data model and it is best it to deal it at that level.|||

well, the column is actually a one that is the IDs of customers, so i think it is conventionally to set it to CHAR. unfortunately for me, it is also conventionally that the IDs of customers containt only number characters, so the two convention contradict at this point !

after reading your suggestions, i think it is much wise to adopt only one of them, or to let the front-end do the check up

|||No, don't let the front end be the only check. Then it cannot be 100% trusted. Do something on the backend if you have the ability to add constraints.|||yes, that's always a problem! thx for the remainder

Monday, March 12, 2012

How to config a linked server from SQL to DB2

I have a DB2 database 7.2.
(
Server Host Name = SVR1,
Database name = PROD,
schema name = db2admin,
Port number = 50000)
How can I config a linked server to this DB2 database from
SQL. I check the doc find the sample like this:
EXEC sp_addlinkedserver
@.server='DB2',
@.srvproduct='Microsoft OLE DB Provider for DB2',
@.catalog='DB2',
@.provider='DB2OLEDB',
@.provstr='Initial Catalog=PUBS;Data
Source=DB2;HostCCSID=1252;Network Address=XYZ;Network
Port=50000;Package Collection=admin;Default Schema=admin;'
I have a little bit confuse with the connect string
@.provstr, anybody can tell me how to mapping my DB2
information to this @.provstr?
I try this wouldn't work
@.provstr='Initial
Catalog=PROD;DataSource=DB2;HostCCSID=1252;Network
Address=SVR1;Network Port=50000;Package
Collection=db2admin;Default Schema=db2admin;'
I got error message: Error 7403: Could not locate registry
entry for OLE DB provider 'DB2OLEDB' OLE DB error trace
[Non-interface error: Provider not registered]
Thanks,
HGDo u have DB2 client installed in your machine,
Thanks
Hari
MCDBA
"HG" <Hansen.gu@.aegoncanada.ca> wrote in message
news:008401c3ae0b$069335d0$a101280a@.phx.gbl...
> I have a DB2 database 7.2.
>
> Server Host Name = SVR1,
> Database name = PROD,
> schema name = db2admin,
> Port number = 50000)
> How can I config a linked server to this DB2 database from
> SQL. I check the doc find the sample like this:
> EXEC sp_addlinkedserver
> @.server='DB2',
> @.srvproduct='Microsoft OLE DB Provider for DB2',
> @.catalog='DB2',
> @.provider='DB2OLEDB',
> @.provstr='Initial Catalog=PUBS;Data
> Source=DB2;HostCCSID=1252;Network Address=XYZ;Network
> Port=50000;Package Collection=admin;Default Schema=admin;'
>
> I have a little bit confuse with the connect string
> @.provstr, anybody can tell me how to mapping my DB2
> information to this @.provstr?
> I try this wouldn't work
> @.provstr='Initial
> Catalog=PROD;DataSource=DB2;HostCCSID=1252;Network
> Address=SVR1;Network Port=50000;Package
> Collection=db2admin;Default Schema=db2admin;'
> I got error message: Error 7403: Could not locate registry
> entry for OLE DB provider 'DB2OLEDB' OLE DB error trace
> [Non-interface error: Provider not registered]
> Thanks,
> HG|||Yes, I do have DB2 client installed locally.
>--Original Message--
>Do u have DB2 client installed in your machine,
>Thanks
>Hari
>MCDBA
>"HG" <Hansen.gu@.aegoncanada.ca> wrote in message
>news:008401c3ae0b$069335d0$a101280a@.phx.gbl...
>> I have a DB2 database 7.2.
>> Server Host Name = SVR1,
>> Database name = PROD,
>> schema name = db2admin,
>> Port number = 50000)
>> How can I config a linked server to this DB2 database
from
>> SQL. I check the doc find the sample like this:
>> EXEC sp_addlinkedserver
>> @.server='DB2',
>> @.srvproduct='Microsoft OLE DB Provider for DB2',
>> @.catalog='DB2',
>> @.provider='DB2OLEDB',
>> @.provstr='Initial Catalog=PUBS;Data
>> Source=DB2;HostCCSID=1252;Network Address=XYZ;Network
>> Port=50000;Package Collection=admin;Default
Schema=admin;'
>>
>> I have a little bit confuse with the connect string
>> @.provstr, anybody can tell me how to mapping my DB2
>> information to this @.provstr?
>> I try this wouldn't work
>> @.provstr='Initial
>> Catalog=PROD;DataSource=DB2;HostCCSID=1252;Network
>> Address=SVR1;Network Port=50000;Package
>> Collection=db2admin;Default Schema=db2admin;'
>> I got error message: Error 7403: Could not locate
registry
>> entry for OLE DB provider 'DB2OLEDB' OLE DB error trace
>> [Non-interface error: Provider not registered]
>> Thanks,
>> HG
>
>.
>

Friday, February 24, 2012

How to combine two columns into one in an sql

I have an stored procedure that returns 3 columns. Month, Date, and Total Number of Calls.

Here is the stored Proc:

SELECTDATEPART(mm, CALLSTARTTIME) , DATEPART(dd, CALLSTARTTIME),COUNT(*)

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS = '1')AND(PINCODEIS NOT NULL)

GROUP BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

ORDER BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

It returns a table:

MONTH DATE TOTAL NUMBER OF CALLS
======= ===== ===========
1 1 10

1 2 15

My question is: is it possible to combine the Month and Date column into one column. e.g.

Date Total Number of Calls
==== ==============
1/1 10
1/2 15

Please Help, Thanks in advance :)

SELECT CONVERT(nvarchar(2),DATEPART(mm, CALLSTARTTIME)) + '/' + CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME)) AS [Date],COUNT(*)

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS = '1')AND(PINCODEIS NOT NULL)

GROUP BY DATEPART(mm, CALLSTARTTIME)) + '/' + CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME))

ORDER BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

|||

thx, I did some configuration. works like a charm

SELECT CONVERT(nvarchar(2),DATEPART(mm, CALLSTARTTIME)) + '/' +CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME))AS[Date],COUNT(*)

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS = '1')AND(PINCODEIS NOT NULL)

GROUP BY DATEPART(mm, CALLSTARTTIME) ,DatePart(dd, Callstarttime),CONVERT(nvarchar(2),DATEPART(mm, CALLSTARTTIME)) + '/' +CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME))

ORDER BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

Sunday, February 19, 2012

How to choose the hardware for SQL Server wit large data

Hi,
I have a large data base and data keeps adding daily. I have the current
number of rows and row size. How do i calculate the hardware power required
for such data? is there any method to calculate that? using which i may go
for server with 10 processcer with 1tb hard drive and some 5gb ram.
Below is my data detail.
Table Current Rows Daily addition Chars per Row
table 1 6,900,000 10000 30
table 2 4,000,000 5000 85
table 3 4,000,000 5000 35
table 4 2,000,000 2500 30
table 5 20,000 2500 65
table 6 4,000,000 5000 105
Please help me.
Regards,
Kiran7,000,000 is not a big table in database ...
I had one back in 2002 with more than 150,000,000 rows (in an automatic
partitionned view - ok) (Hardware : 2 processors, < 40GBytes).
By the way, you need to evaluate more points:
* peek number of simultaneous connections / peek value of 'count per minute'
* mean size of row data stored and returned
...
Sl.
"N Kiran Kumar" <N Kiran Kumar@.discussions.microsoft.com> a écrit dans le
message de news: 46BB099A-37CB-4D25-9728-1110CB9804CD@.microsoft.com...
> Hi,
> I have a large data base and data keeps adding daily. I have the
> current
> number of rows and row size. How do i calculate the hardware power
> required
> for such data? is there any method to calculate that? using which i may go
> for server with 10 processcer with 1tb hard drive and some 5gb ram.
> Below is my data detail.
> Table Current Rows Daily addition Chars per Row
> table 1 6,900,000 10000 30
> table 2 4,000,000 5000 85
> table 3 4,000,000 5000 35
> table 4 2,000,000 2500 30
> table 5 20,000 2500 65
> table 6 4,000,000 5000 105
> Please help me.
> Regards,
> Kiran
>
>|||Hi
Along with other posts!!
You should also talk to your hardware supplier! The hardware does depend on
what you are doing with your database and usually that tends to change over
time with new releases/requirements etc... Looking at the current hardware
and performance counters you may get some idea, whatever you come up with may
have to be compromised by budget.
As far as disc space goes you will probably need to intellegently place your
data, therefore look for more spindles (or the ability to add more) rather
than fewer discs with higher capacity.
This site and these articles may help
http://www.sql-server-performance.com/articles/per/hardware_planning_p1.aspx
John
"N Kiran Kumar" wrote:
> Hi,
> I have a large data base and data keeps adding daily. I have the current
> number of rows and row size. How do i calculate the hardware power required
> for such data? is there any method to calculate that? using which i may go
> for server with 10 processcer with 1tb hard drive and some 5gb ram.
> Below is my data detail.
> Table Current Rows Daily addition Chars per Row
> table 1 6,900,000 10000 30
> table 2 4,000,000 5000 85
> table 3 4,000,000 5000 35
> table 4 2,000,000 2500 30
> table 5 20,000 2500 65
> table 6 4,000,000 5000 105
> Please help me.
> Regards,
> Kiran
>
>