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

Friday, March 30, 2012

Increase number of process(thread)

Hello all,

A software that connects SQL Server via ODBC uses 12 process at the same
time when I look at the process info(panel). Is it possible to increase
number of process (or thread) for a specific database? Is there any
parameter?

Thanks in advance,
Do.

--
Message posted via http://www.sqlmonster.comDo Park via SQLMonster.com (forum@.nospam.SQLMonster.com) writes:
> A software that connects SQL Server via ODBC uses 12 process at the same
> time when I look at the process info(panel). Is it possible to increase
> number of process (or thread) for a specific database? Is there any
> parameter?

You can change the number of permitted connections with

sp_configure 'user connections', 100 -- 100 is an example here

This is a server-wide setting. There is no per-database setting for this
(and neither would it be really meaningful).

However, the default for this option is 0, which means that the server
configures as it goes on.

Are you getting any error messages about running out of connections?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||
Do Park via SQLMonster.com wrote:
> Hello all,
> A software that connects SQL Server via ODBC uses 12 process at the same
> time when I look at the process info(panel). Is it possible to increase
> number of process (or thread) for a specific database? Is there any
> parameter?
> Thanks in advance,
> Do.
> --
> Message posted via http://www.sqlmonster.com

You will find that this is a programed function of the software itself,
not SQL Server.

See if there is a configuration setting you can use to adjust it.

You could also download a copy of the database monitor I have developed
which will tell you what load the software application is having on the
server. This will help determine if it is safe to up the number of
connections or not. It will also tell you if they are locking
themselves out.

You can download it from http://dbmonitor.tripod.com.

Increase number by 1

Hello all,
I have, what i think, is a unique problem that i'm hoping some of you can help me on.

I need to create a record number that is incremented by 1 whenever someone adds a new record to the database. For example, records numbering 1,2,3 are in the database. When the users adds a new record, SQL takes the last recordno, 3 in this case, and adds 1 to it thus producing 4.

Also, i need to have the ability to replace deleted record numbers with new ones. Using the example above, say a user deletes record number 2. Whenever someone adds a new record, sql would see the missing number and assign the new record that number.

I hope i'm making sense here. Does anyone have any ideas about this? Any articles on the web that someone could point me to?

Thanks.
Richard M.hi richard,
i guess you need to do this by coding urself. u can use the feature in Sql server to increment the number by one but i don't think its possible to replace the deleted number.

so the better solution will be to add the incrementing number programatically. first declare int data type in sql server and assign 1 for the first record. for new records, check whether any number is missing and try to add new into that.

for eg, if you have 10 records, then no of 10th record should be 10 else some record is deleted. so u can use loop to check which number is missing.

i hope u can do the coding.

Wednesday, March 28, 2012

Incorrect week number with DATENAME in localized query

Hi,

I'm trying to use the DATENAME function to get a correct Dutch week number, but the DATENAME function seems not to return a localized week number. This is how I have tested it:

-- Set language to English
SET LANGUAGE us_English

-- Declare to dates 12/30/2006 and 12/31/2006
DECLARE @.Dec30 AS DATETIME SET @.Dec30 = CONVERT(DateTime, '2006-12-30')
DECLARE @.Dec31 AS DATETIME SET @.Dec31 = CONVERT(DateTime, '2006-12-31')

-- Return information about the declared dates in English
SELECT @.Dec30 as date1, DATENAME(week, @.Dec30) as week1, DATENAME(weekday, @.Dec30) as day1,
@.Dec31 as date2, DATENAME(week, @.Dec31) as week2, DATENAME(weekday, @.Dec31) as day2

-- Set language to Dutch
SET LANGUAGE Dutch

-- Return information about the declared dates in Dutch
SELECT @.Dec30 as date1, DATENAME(week, @.Dec30) as week1, DATENAME(weekday, @.Dec30) as day1,
@.Dec31 as date2, DATENAME(week, @.Dec31) as week2, DATENAME(weekday, @.Dec31) as day2

In both the English and Dutch results Saturday (12/30/2006) has week number 52 and Sunday (12/31/2006) has week number 53, but this is incorrect for the Dutch language. Sunday should also have week number 52, because the week starts on Monday in The Netherlands.

What am I doing wrong here and how can I get the correct localized week numbers from SQL Server? (I'm using SQL Server 2000 + SP4)

Thanks in advance.

SET Language is used configure the following options, DateFormat, DateFirst, Names of the Month & Names of the Days. So your in the rite direction to get your result..

BUT,

Unfortuantlly SQL Server won't help you to get the proper Week Number. Bcs they are not following ISO standard as you think. The Week 1 always = 1 - jan -any year. So sometimes you will get wrong week number.

The best approach to get the week number is use the custom function to get the week number.

Create Function dbo.MyWeekNo(@.dateFirst int, @.DateValue as DateTime) Returns Int
As
Begin
Declare @.Date as Datetime
declare @.Date2 as Datetime
Declare @.Week as int
Select @.Date = Convert(Varchar,Year(@.DateValue)) + '-01-01', @.Date2=DateAdd(DD,-1,@.Date)

Select @.Week = Case When WeekNo=0 Then dbo.MyWeekNo(@.dateFirst,@.Date2) Else WeekNo End
From
(
Select
Case When DatePart(W,@.Date) >= @.dateFirst Then DatePart(WW,@.DateValue) -1
Else DatePart(WW,@.DateValue) End WeekNo
) as Weeks

Return @.Week;
End

|||

Hi ManiD,

Your function is very close to the function I'm using for years now:

CREATE FUNCTION dbo.DutchWeek(@.DATE AS DateTime) RETURNS Int AS
BEGIN
IF @.DATE IS NULL RETURN NULL;

DECLARE @.JANFIRST AS DateTime
DECLARE @.WEEKDAY AS Int
DECLARE @.DAY AS Int
DECLARE @.DAYOFYEAR AS Int
DECLARE @.WEEKNUMBER AS Int

-- Get Januari the first of the year of @.DATE
SET @.JANFIRST = CONVERT(datetime, '1/1/' + CONVERT(varchar, YEAR(@.DATE)))

-- Calculate the number of the day where 0 = Monday, 1 = Tuesday, etc...
SET @.WEEKDAY = CONVERT(Int, @.JANFIRST) % 7

-- Calculate the (zero-bases) day number (0..265)
SET @.DAYOFYEAR = CONVERT(integer, @.DATE - @.JANFIRST)
-- Calculate the dutch week number
SET @.WEEKNUMBER = (@.DAYOFYEAR + @.WEEKDAY) / 7 +
CASE WHEN @.WEEKDAY > 3 THEN 0 ELSE 1 END

-- When week number is 0, get the weeknumber of the last week of the
-- previous year
IF @.WEEKNUMBER = 0
SET @.WEEKNUMBER = dbo.DutchWeek('12/31/' +
CONVERT(varchar, YEAR(@.DATE)-1));
RETURN @.WEEKNUMBER;
END

I use this function for years, but always had the feeling SQL Server should do this for me. But this is not the case, is it?

Wednesday, March 21, 2012

incorrect number of rows

I have a table 'detail_curr' with a column called
'tams_id'.
1. If the column is indexed (non-cluster,non-unique),
select count(*) from detail_curr
where tams_id is null;
(result): 4003464
2. If the column is NOT indexed,
(result): 3902727
What's wrong? Any help is appreciated.Check out:
http://support.microsoft.com/default.aspx?scid=kb;en-us;814509
--
Hope this helps.
Dan Guzman
SQL Server MVP
--
SQL FAQ links (courtesy Neil Pike):
http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--
"yren" <yren@.cc3.com> wrote in message
news:065801c35c8b$8d2f1b30$a501280a@.phx.gbl...
> I have a table 'detail_curr' with a column called
> 'tams_id'.
> 1. If the column is indexed (non-cluster,non-unique),
> select count(*) from detail_curr
> where tams_id is null;
> (result): 4003464
> 2. If the column is NOT indexed,
> (result): 3902727
> What's wrong? Any help is appreciated.|||Thanks. That's very helpful.
yren
>--Original Message--
>Check out:
>http://support.microsoft.com/default.aspx?scid=kb;en-
us;814509
>--
>Hope this helps.
>Dan Guzman
>SQL Server MVP
>--
>SQL FAQ links (courtesy Neil Pike):
>http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
>http://www.sqlserverfaq.com
>http://www.mssqlserver.com/faq
>--
>

Monday, March 19, 2012

Incorrect host-column number found in BCP format-file

Hi guys, would appreciate if you can shed some light on this.

Sorry to be a pain, can you tell me what is wrong with the following:

for /F %%i in ('dir /b /on c:\bcp\pc*.txt') do bcp Inventory..pc in
%%i -fc:\bcp\bcp.fmt -T -S CHICKYy
where CHICKYy is the server

bcp.fmt

8.00.194
6
1 SQLCHAR 0 20 ", " 0 filler_1 ""
2 SQLCHAR 0 8 "\r\n" 1 computer_name ""
3 SQLCHAR 0 20 ", " 0 filler_2 ""
4 SQLCHAR 0 16 "\r\n" 2 ip_address ""
5 SQLCHAR 0 20 ", " 0 filler_3 ""
6 SQLCHAR 0 60 "\r\n" 3 operating_system ""

pc1.txt and other *.txt format is:

JW_193801,
192.168.1.1,
Windows XP,

when I run it I get:

C:\bcp>for /F %i in ('dir /b /on c:\bcp\pc*.txt') do bcp Inventory..pc in
%i -fc:\bcp\bcp.fmt -T -S CHICKYy

C:\bcp>bcp Inventory..pc in pc1.txt -fc:\bcp\bcp.fmt -T -S CHICKYy
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Incorrect host-column number
found in BCP format-file

C:\bcp>bcp Inventory..pc in pc2.txt -fc:\bcp\bcp.fmt -T -S CHICKYy
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Incorrect host-column number
found in BCP format-file

C:\bcp>bcp Inventory..pc in pc3.txt -fc:\bcp\bcp.fmt -T -S CHICKYy
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Incorrect host-column number
found in BCP format-file

C:\bcp>bcp Inventory..pc in pc4.txt -fc:\bcp\bcp.fmt -T -S CHICKYy
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Incorrect host-column number
found in BCP format-file

C:\bcp>bcp Inventory..pc in pc5.txt -fc:\bcp\bcp.fmt -T -S CHICKYy
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Incorrect host-column number
found in BCP format-file

The sql table has 3 columns:

Sorry to be a pain.

--

---------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://mail.spaminspector.comMichelle Hillard (mhillard@.craized.tv) writes:
> bcp.fmt
> 8.00.194
> 6
> 1 SQLCHAR 0 20 ", " 0 filler_1 ""
> 2 SQLCHAR 0 8 "\r\n" 1 computer_name ""
> 3 SQLCHAR 0 20 ", " 0 filler_2 ""
> 4 SQLCHAR 0 16 "\r\n" 2 ip_address ""
> 5 SQLCHAR 0 20 ", " 0 filler_3 ""
> 6 SQLCHAR 0 60 "\r\n" 3 operating_system ""
>...
> C:\bcp>for /F %i in ('dir /b /on c:\bcp\pc*.txt') do bcp Inventory..pc in
> %i -fc:\bcp\bcp.fmt -T -S CHICKYy
> C:\bcp>bcp Inventory..pc in pc1.txt -fc:\bcp\bcp.fmt -T -S CHICKYy
> SQLState = S1000, NativeError = 0
> Error = [Microsoft][ODBC SQL Server Driver]Incorrect host-column number
> found in BCP format-file

BCP's is not famous for its self-explanatory messages.

My guess goes to the version number. It should say 8.0, not 8.00.194.

(And if you are running 8.00.194 somewhere, you should download and
install SP3 for SQL Server to get a couple of important bug and
security fixes.)

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Monday, March 12, 2012

Inconsistent sort order using ORDER BY clause

I am getting the resultset sorted differently if I use a column number in the ORDER BY clause instead of a column name.

Product: Microsoft SQL Server Express Edition
Version: 9.00.1399.06
Server Collation: SQL_Latin1_General_CP1_CI_AS

for example,

create table test_sort
( description varchar(75) );

insert into test_sort values('Non-A');
insert into test_sort values('Non-O');
insert into test_sort values('Noni');
insert into test_sort values('Nons');

then execute the following selects:
select
*
from
test_sort
order by
cast( 1 as nvarchar(75));

select
*
from
test_sort
order by
cast( description as nvarchar(75));

Resultset1
-
Non-A
Non-O
Noni
Nons

Resultset2
-
Non-A
Noni
Non-O
Nons

Any ideas?As far as i figured your query out, i am just wondering why this works for you as the 1 will be casted to a constant string which should not be allowed in the order by clause. Are you sure this works for you ?

Jens K. Suessmeyer.

http://www.sqlserver2005.de|||First, you are running the release version of 2005. You should install at least SP1.

Second, if you install SP1, you would see an error:

Msg 408, Level 16, State 1, Line 9
A constant expression was encountered in the ORDER BY list, position 1.

Because you are sorting by the NUMBER 1, not column 1 by using the cast. So basically you have no sort.

Inconsistent performance from queues

Hi everyone! I have a very brief question... I have 10 queues in my database and each of them are sent equal number of messages... There are instances where they execute/activate the stored procedures very fast but there are times where they don't, does anyone have an idea why this happens?

Thank you very much for taking the time to read my post. :)

What is inconsistent, the activation of the first proc for the queue, or the activation of subsequent procs for the queue.

How many messages are being sent to the queues?

What do the procs do?

|||

I'm sorry I wasn't clear abt my question :)

The exact scenario is: I have 10 queues. Each of these queues activate a stored procedure that inserts 150 records in a table. I insert 5 messages for each queue. So, in total, I insert 7500 records in the said table.

The thing is, I don't get the same speed at the everytime. Sending all the messages in all the queues will take up 30 seconds, but there are instances that it takes 50 seconds or more. When I check the table that I'm inserting to during the sending of messages, for a certain time it would insert 4500 at such a fast rate and then would be idle for a while. By idle, I meant that no additional rows are being added, even if the messages have all been sent in the queues.

If it's necessary for me to post the SQL code for this, pls tell me.

Thanks a bunch, guys! :)

|||Please, your situatation would indicate a designe feature and performance issue with your code on an issue witht eh SB code|||

This is the SQL code for sending the message:

BEGIN TRANSACTION ;

DECLARE @.message XML ;

SET @.message = '<root><ctr counter="' + CAST(@.Ctr AS nvarchar(20)) + '"></ctr></root>';

DECLARE @.conversationHandle UNIQUEIDENTIFIER ;

BEGIN DIALOG CONVERSATION @.conversationHandle

FROM SERVICE InitiatorService1

TO SERVICE 'TargetService1'

ON CONTRACT Contract1

WITH ENCRYPTION = OFF;

SEND ON CONVERSATION @.conversationHandle

MESSAGE TYPE MsgType1 (@.message) ;

COMMIT TRANSACTION ;

This is the SQL code for the stored proc that is activated when message is received by the queue:

WHILE (1 = 1)

BEGIN

DECLARE @.conversation_handle UNIQUEIDENTIFIER,

@.conversation_group_id UNIQUEIDENTIFIER,

@.message_body XML,

@.message_type_name NVARCHAR(128);

BEGIN TRANSACTION ;

WAITFOR(GET CONVERSATION GROUP @.conversation_group_id

FROM [dbo].[TargetQueue1]), TIMEOUT 1 ;

IF @.conversation_group_id IS NULL

BEGIN

ROLLBACK TRANSACTION ;

BREAK ;

END ;

WHILE 1 = 1

BEGIN

RECEIVE TOP(1)

@.conversation_handle = conversation_handle,

@.message_type_name = message_type_name,

@.message_body =

CASE

WHEN validation = 'X' THEN CAST(message_body AS XML)

ELSE CAST(N'<none/>' AS XML)

END

FROM [dbo].[TargetQueue1]

WHERE conversation_group_id = @.conversation_group_id ;

IF @.@.ROWCOUNT = 0 OR @.@.ERROR <> 0 BREAK;

END CONVERSATION @.conversation_handle ;

END;

COMMIT TRANSACTION ;

DECLARE @.Ctr int

SELECT @.Ctr = @.message_body.value('(/root/ctr/@.counter)[1]', 'int')

EXEC InsertRecords2 @.Ctr, 1 -- stored proc that inserts 150 records in the table

END

|||

Looks like the stored procedure above will always receive messages from TargetQueue1. How does it receive messages from the other 9 queues?

Also, you are doing the insert outside the message loop. If you receive more than one message in a conversation group (doesn't look like you are from your SEND code), you will end up with inserting only the last message received. Also the insertion is not being done in the same transaction scope as the receive... so it is possible in case of failure that you would lose some messages.

|||Is it also not the case that the rollback will result in the queue being disabled due to poison message protection. it should really commit if no conversation group is found.|||

I have 10 of this code, one for each queue.

I will try to rewrite my code and take into account all of your inputs. Will give you feedback ASAP.

Thank you very much, you've all been very helpful :)

|||

Hi guys, I've changed my code for RECEIVE into this:

DECLARE @.conversation_handle UNIQUEIDENTIFIER,

@.conversation_group_id UNIQUEIDENTIFIER,

@.message_body XML,

@.message_type_name NVARCHAR(128);

WHILE (1 = 1)

BEGIN

BEGIN TRANSACTION ;

RECEIVE TOP(1)

@.conversation_handle = conversation_handle,

@.message_type_name = message_type_name,

@.message_body =

CASE

WHEN validation = 'X' THEN CAST(message_body AS XML)

ELSE CAST(N'<none/>' AS XML)

END

FROM [dbo].[TargetQueue1] ;

IF (@.@.ROWCOUNT = 0)

BEGIN

ROLLBACK TRANSACTION

BREAK ;

END

END CONVERSATION @.conversation_handle ;

COMMIT TRANSACTION ;

DECLARE @.Ctr int

SELECT @.Ctr = @.message_body.value('(/root/ctr/@.counter)[1]', 'int')

EXEC InsertRecords2 @.Ctr, 1

END

|||

Is there any place in this code where locking is being made which delays some of the insertion that I'm doing? That's my only speculation but I can't seem to pinpoint at which part this happens.

I didn't include the stored procedure for insertion inside the transactions for fear that this may delay the entire process more. I'll try now with that inside the transactions.

Thanks again for looking into this. I'm just new with the technology, so I hope you could understand why there are some flaws in my code :)

|||

I just noticed that I'm only ending the conversation in the TargetQueue and never in the InitiatorQueue (this is associated with the service that initiated the conversation). Could this be a possible cause? I noticed that after all the processing, the InitiatorQueue contains a lot of message with message type of http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog

Thanks again! :D

Sunday, February 19, 2012

In SQL Server,I need to pull the records that have improper international phone number of format

Hi can you please help me to come up with a solution where i can pull records that have improper international telephone number format. like for example: These are set of records that have length 16 characters.

TelNumber.

091-3 4-43 -5678 ->here including numbers it even counts the spaces ,'-' between numbers and gives length as 16.

509--66-4 3-8887

670- 67--077-546.

908-898-654-3421 ->only 4th and 5th records are valid records that match the standard format we follow:

972-567-553-7689 ccc-aaa-nnn-nnnn where ccc =country code;aaa =area code;nnn-nnnn =phone number

I need a query that can pull first 3 record types...

thanks,

Comalkatar

I think that this will work for you:

Code Snippet


DECLARE @.Phones table
( TelNumber varchar(20) )


SET NOCOUNT ON


INSERT INTO @.Phones VALUES ( '091-3 4-43 -5678' )
INSERT INTO @.Phones VALUES ( '509--66-4 3-8887' )
INSERT INTO @.Phones VALUES ( '670- 67--077-546.' )
INSERT INTO @.Phones VALUES ( '908-898-654-3421' )
INSERT INTO @.Phones VALUES ( '972-567-553-7689' )


SELECT TelNumber
FROM @.Phones
WHERE TelNumber NOT 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]'

TelNumber
--
091-3 4-43 -5678
509--66-4 3-8887
670- 67--077-546.

|||

Here You go...(using Regular Expression)

Code Snippet

Create Table #telephones (

TelNumber Varchar(100)

);

Insert Into #telephones Values('091-3 4-43 -5678');

Insert Into #telephones Values('509--66-4 3-8887');

Insert Into #telephones Values('70- 67--077-546.');

Insert Into #telephones Values('908-898-654-3421');

Insert Into #telephones Values('972-567-553-7689');

Select

*

From

#telephones

Where

TelNumber NOT 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]'