Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Wednesday, March 21, 2012

Grab IDENTITY from called stored procedure for use in second stored procedure in ASP.NET p

I have a sub that passes values from my form to my stored procedure. The stored procedure passes back an @.@.IDENTITY but I'm not sure how to grab that in my asp page and then pass that to my next called procedure from my aspx page. Here's where I'm stuck:

Public Sub InsertOrder()

Conn.Open()

cmd = New SqlCommand("Add_NewOrder", Conn)
cmd.CommandType = CommandType.StoredProcedure

' pass customer info to stored proc
cmd.Parameters.Add("@.FirstName", txtFName.Text)
cmd.Parameters.Add("@.LastName", txtLName.Text)
cmd.Parameters.Add("@.AddressLine1", txtStreet.Text)
cmd.Parameters.Add("@.CityID", dropdown_city.SelectedValue)
cmd.Parameters.Add("@.Zip", intZip.Text)
cmd.Parameters.Add("@.EmailPrefix", txtEmailPre.Text)
cmd.Parameters.Add("@.EmailSuffix", txtEmailSuf.Text)
cmd.Parameters.Add("@.PhoneAreaCode", txtPhoneArea.Text)
cmd.Parameters.Add("@.PhonePrefix", txtPhonePre.Text)
cmd.Parameters.Add("@.PhoneSuffix", txtPhoneSuf.Text)

' pass order info to stored proc
cmd.Parameters.Add("@.NumberOfPeopleID", dropdown_people.SelectedValue)

cmd.Parameters.Add("@.BeanOptionID", dropdown_beans.SelectedValue)
cmd.Parameters.Add("@.TortillaOptionID", dropdown_tortilla.SelectedValue)

'Session.Add("FirstName", txtFName.Text)

cmd.ExecuteNonQuery()

cmd = New SqlCommand("Add_EntreeItems", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@.CateringOrderID", get identity from previous stored proc) <--------

Dim li As ListItem
Dim p As SqlParameter = cmd.Parameters.Add("@.EntreeID", Data.SqlDbType.VarChar)
For Each li In chbxl_entrees.Items
If li.Selected Then
p.Value = li.Value
cmd.ExecuteNonQuery()
End If
Next

Conn.Close()

I want to somehow grab the @.CateringOrderID that was created as an end product of my first called stored procedure (Add_NewOrder) and pass that to my second stored procedure (Add_EntreeItems)

Sorry that I don't know the exact syntax off hand, but if your stored procedure is returning the @.@.Identity as it's return, then you need to add the return parameter to the first command.

It'd be something like (sorry again, this is from memory):

cmd.Parameters.Add(New SqlParameter("@.CateringOrderID",RETURN_VALUE)) or something similiar, then at later add

dim ret as long = cmd.Parameters("@.CateringOrderID").value

Or something very similiar.

If your stored procedure is using an output parameter, you need to do the same thing, but instead of calling it RETURN_VALUE, it's like OUTPUT_VALUE or something. There is a more descriptive way of adding parameters that you can tell it if it's return value type parameter, an input type, or an output type. Once you find that, that's 90% of your solution.

|||thanks for your input, still working on it.|||

right now I'm trying to use this to obtain the returned @.@.IDENTITY from my first stored proc:

Dim NewCateringOrderIDAsInteger =CType(cmd.ExecuteScalar(),Integer)

|||Yes, that will work if the identity is the first and only result the stored procedure generates. To turn off empty resultsets (From inserts, updates, etc that go on in the stored procedure), place a SET NOCOUNT ON at the beginning of the stored procedure, and place a SET NOCOUNT OFF right before your SELECT SCOPE_IDENTITY(). Then optionally add SET NOCOUNT ON again if there are any other database modification statements after that, and finally SET NOCOUNT OFF at the very end.|||

Here we go, thanks for the start

http://aspnet.4guysfromrolla.com/articles/062905-1.aspx

|||You can do something like this:

SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlCommand myCommand = new SqlCommand("sproc_name",myConnection);

// Attach the parameters to the myCommand object

Set the parameter direction of the commad object to returnValue

myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();

int identity = (int) myCommand.Parameters["MyReturnValue"].value;

// now that you have identity you can send into next stored procedure

Also remember that you can also send the values from one stored procedure to another stored procedure using T-SQL queries this way you dont need to return the identity to the presentation layer.

CREATE PROCEDURE #test_proc
AS
INSERT INTO #test VALUES(123)

RETURN SCOPE_IDENTITY()|||Here is another way which simply calls one stored procedure from another stored procedure:

CREATE TABLE #Names (k1 int identity(1,1) , name varchar(20) )

CREATE TABLE #Phone (k2 int identity(1,1), phone varchar(20), k1 int )

CREATE PROCEDURE #insert_name

@.Name varchar(20)

AS

DECLARE @.returnValue int

INSERT INTO #Names VALUES(@.Name)

SET @.returnValue = SCOPE_IDENTITY()

EXEC #insert_phone @.nameID = @.returnValue

EXEC #insert_name @.Name = 'AzamSharp'

SELECT * FROM #Names
SELECT * FROM #phone|||thanks but in this case, I'm not able to send the IDENTITY to another stored procedure because I need to run through another stored proc to insert checkboxlist items and must do this through another call where I loop through each item in the checkbox. I suppose it would be much better to do what you say and just loop through the checkboxlist items first then pass one string to the same stored procedure...actually I'll try that way instead this time since I do know how to pass the identity or other parameters to other stored procs from within the same stored proc|||

Create proc ( int @.id Output) AS

Select * from table ;

Select @.id=@.@.identity;

===============================

cmd.Parameters.Add(@.id,SqlDbType.Int32);

cmd.Parameters["@.id"].Direction=ParameterDirection.Output;

conn.Open();

cmd.ExecuteNonQuery();

conn.Close();

return (int)cmd.Parameters["@.id"].value;

============================

i am not fimiliar with english, may be missing spell but here is a idea which i can work through out.

Monday, March 19, 2012

Goofy Bullsh!t SQL Server 2005 Date Values

What's with this software? Every day its a new surprise with some goofy
bullsh!t.
I finally make time to try to finish building out ASP.NET 2.0 Membership
logging and reporting code and today its user data in the SQL Server 2005
aspnet_Membership table such as LastLockoutDate and FailedPassword with date
values for all users entered as 1/1/1754.
Not only is this goofy bullsh!t it is grossly incorrect goofy bullsh!t. I
have used one of my three test users to test getting locked out so I could
learn to use the Unlock method and I certainly did not enter that user's
incorrect credentials on 1/1/1754. I have no idea how the other users have
data has been manipulated either.
What the heck is going on here?
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/If a Goofy programmer read the goofy doc before posting goofy messages, he
would fined that 1/1/1754 for the lockout data means it has not been locked
out.
http://msdn2.microsoft.com/en-us/library/system.web.security.activedirectorymembershipprovider.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"clintonG" <csgallagher@.REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:%230DLIENiGHA.1264@.TK2MSFTNGP05.phx.gbl...
> What's with this software? Every day its a new surprise with some goofy
> bullsh!t.
> I finally make time to try to finish building out ASP.NET 2.0 Membership
> logging and reporting code and today its user data in the SQL Server 2005
> aspnet_Membership table such as LastLockoutDate and FailedPassword with
> date values for all users entered as 1/1/1754.
> Not only is this goofy bullsh!t it is grossly incorrect goofy bullsh!t. I
> have used one of my three test users to test getting locked out so I could
> learn to use the Unlock method and I certainly did not enter that user's
> incorrect credentials on 1/1/1754. I have no idea how the other users have
> data has been manipulated either.
> What the heck is going on here?
> <%= Clinton Gallagher
> NET csgallagher AT metromilwaukee.com
> URL http://www.metromilwaukee.com/clintongallagher/
>|||DOH!!!
Sorry, couldn't resist...|||I don't use the AD Provider but I do see by the document you refer to that
the explanation of this goofy date sh!t is much more lucid and complete than
in other documents I did and have read [1] but still happen to have missed
the pithy sentence that is supposed to pass for documentation.
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
[1]
http://msdn2.microsoft.com/en-us/library/system.web.security.membershipuser.lastlockoutdate.aspx
"Roger Wolter[MSFT]" <rwolter@.online.microsoft.com> wrote in message
news:etI$pGOiGHA.4512@.TK2MSFTNGP02.phx.gbl...
> If a Goofy programmer read the goofy doc before posting goofy messages, he
> would fined that 1/1/1754 for the lockout data means it has not been
> locked out.
> http://msdn2.microsoft.com/en-us/library/system.web.security.activedirectorymembershipprovider.aspx
>
> --
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> "clintonG" <csgallagher@.REMOVETHISTEXTmetromilwaukee.com> wrote in message
> news:%230DLIENiGHA.1264@.TK2MSFTNGP05.phx.gbl...
>> What's with this software? Every day its a new surprise with some goofy
>> bullsh!t.
>> I finally make time to try to finish building out ASP.NET 2.0 Membership
>> logging and reporting code and today its user data in the SQL Server 2005
>> aspnet_Membership table such as LastLockoutDate and FailedPassword with
>> date values for all users entered as 1/1/1754.
>> Not only is this goofy bullsh!t it is grossly incorrect goofy bullsh!t.
>> I have used one of my three test users to test getting locked out so I
>> could learn to use the Unlock method and I certainly did not enter that
>> user's incorrect credentials on 1/1/1754. I have no idea how the other
>> users have data has been manipulated either.
>> What the heck is going on here?
>> <%= Clinton Gallagher
>> NET csgallagher AT metromilwaukee.com
>> URL http://www.metromilwaukee.com/clintongallagher/
>

Goofy Bullsh!t SQL Server 2005 Date Values

What's with this software? Every day its a new surprise with some goofy
bullsh!t.
I finally make time to try to finish building out ASP.NET 2.0 Membership
logging and reporting code and today its user data in the SQL Server 2005
aspnet_Membership table such as LastLockoutDate and FailedPassword with date
values for all users entered as 1/1/1754.
Not only is this goofy bullsh!t it is grossly incorrect goofy bullsh!t. I
have used one of my three test users to test getting locked out so I could
learn to use the Unlock method and I certainly did not enter that user's
incorrect credentials on 1/1/1754. I have no idea how the other users have
data has been manipulated either.
What the heck is going on here?
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/If a Goofy programmer read the goofy doc before posting goofy messages, he
would fined that 1/1/1754 for the lockout data means it has not been locked
out.
http://msdn2.microsoft.com/en-us/li...ipprovider.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
news:%230DLIENiGHA.1264@.TK2MSFTNGP05.phx.gbl...
> What's with this software? Every day its a new surprise with some goofy
> bullsh!t.
> I finally make time to try to finish building out ASP.NET 2.0 Membership
> logging and reporting code and today its user data in the SQL Server 2005
> aspnet_Membership table such as LastLockoutDate and FailedPassword with
> date values for all users entered as 1/1/1754.
> Not only is this goofy bullsh!t it is grossly incorrect goofy bullsh!t. I
> have used one of my three test users to test getting locked out so I could
> learn to use the Unlock method and I certainly did not enter that user's
> incorrect credentials on 1/1/1754. I have no idea how the other users have
> data has been manipulated either.
> What the heck is going on here?
> <%= Clinton Gallagher
> NET csgallagher AT metromilwaukee.com
> URL http://www.metromilwaukee.com/clintongallagher/
>|||DOH!!!
Sorry, couldn't resist...|||I don't use the AD Provider but I do see by the document you refer to that
the explanation of this goofy date sh!t is much more lucid and complete than
in other documents I did and have read [1] but still happen to have miss
ed
the pithy sentence that is supposed to pass for documentation.
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
[1]
http://msdn2.microsoft.com/en-us/li...
ckoutdate.aspx
"Roger Wolter[MSFT]" <rwolter@.online.microsoft.com> wrote in message
news:etI$pGOiGHA.4512@.TK2MSFTNGP02.phx.gbl...
> If a Goofy programmer read the goofy doc before posting goofy messages, he
> would fined that 1/1/1754 for the lockout data means it has not been
> locked out.
> http://msdn2.microsoft.com/en-us/li...ipprovider.aspx
>
> --
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> "clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
> news:%230DLIENiGHA.1264@.TK2MSFTNGP05.phx.gbl...
>

Good values for performance counters

Hi,
I was asked to test an SQL Server to see if it needs a hardware upgrade. I
run performance monitor and added some counters that I had read in books. My
problem is that the books only mention good counters, but they don't tell
what the good values are!
I would be most grateful if you can write some counters with acceptable
ranges to check:
Disk, Memory and CPU.
I have to decide about the current configuration of this production server.
I need criteria!
Thanks in advance.
Leila
Check out the web site http://www.sql-server-performance.com/
Look down toward the bottom of the page where the sorted list of topics. The
numbers are in the articles PerformanceMonitor Counters()
Two books that have these values are:
SQL Server Performance Tuning Distilled by Sanjay Dam
Start to Finish Guide to SQL Server Performance Monitoring by Brian Kelly
which is an eBook available at http://www.netimpress.com/
"Leila" wrote:

> Hi,
> I was asked to test an SQL Server to see if it needs a hardware upgrade. I
> run performance monitor and added some counters that I had read in books. My
> problem is that the books only mention good counters, but they don't tell
> what the good values are!
> I would be most grateful if you can write some counters with acceptable
> ranges to check:
> Disk, Memory and CPU.
> I have to decide about the current configuration of this production server.
> I need criteria!
> Thanks in advance.
> Leila
>
>

Good values for performance counters

Hi,
I was asked to test an SQL Server to see if it needs a hardware upgrade. I
run performance monitor and added some counters that I had read in books. My
problem is that the books only mention good counters, but they don't tell
what the good values are!
I would be most grateful if you can write some counters with acceptable
ranges to check:
Disk, Memory and CPU.
I have to decide about the current configuration of this production server.
I need criteria!
Thanks in advance.
LeilaCheck out the web site http://www.sql-server-performance.com/
Look down toward the bottom of the page where the sorted list of topics. The
numbers are in the articles PerformanceMonitor Counters()
Two books that have these values are:
SQL Server Performance Tuning Distilled by Sanjay Dam
Start to Finish Guide to SQL Server Performance Monitoring by Brian Kelly
which is an eBook available at http://www.netimpress.com/
"Leila" wrote:

> Hi,
> I was asked to test an SQL Server to see if it needs a hardware upgrade. I
> run performance monitor and added some counters that I had read in books.
My
> problem is that the books only mention good counters, but they don't tell
> what the good values are!
> I would be most grateful if you can write some counters with acceptable
> ranges to check:
> Disk, Memory and CPU.
> I have to decide about the current configuration of this production server
.
> I need criteria!
> Thanks in advance.
> Leila
>
>

Good values for performance counters

Hi,
I was asked to test an SQL Server to see if it needs a hardware upgrade. I
run performance monitor and added some counters that I had read in books. My
problem is that the books only mention good counters, but they don't tell
what the good values are!
I would be most grateful if you can write some counters with acceptable
ranges to check:
Disk, Memory and CPU.
I have to decide about the current configuration of this production server.
I need criteria!
Thanks in advance.
LeilaCheck out the web site http://www.sql-server-performance.com/
Look down toward the bottom of the page where the sorted list of topics. The
numbers are in the articles PerformanceMonitor Counters()
Two books that have these values are:
SQL Server Performance Tuning Distilled by Sanjay Dam
Start to Finish Guide to SQL Server Performance Monitoring by Brian Kelly
which is an eBook available at http://www.netimpress.com/
"Leila" wrote:
> Hi,
> I was asked to test an SQL Server to see if it needs a hardware upgrade. I
> run performance monitor and added some counters that I had read in books. My
> problem is that the books only mention good counters, but they don't tell
> what the good values are!
> I would be most grateful if you can write some counters with acceptable
> ranges to check:
> Disk, Memory and CPU.
> I have to decide about the current configuration of this production server.
> I need criteria!
> Thanks in advance.
> Leila
>
>

Monday, March 12, 2012

Good SQL Query

Folks, i've got a table with a column; ACCOUNT VARCHAR(30). All the values numeric though. (leave abt the datatype yet).
The column is clustered indexed.

SELECT * FROM MYTABLE WHERE LEFT(ACCOUNT,3)='123'
execution plan shows CLUSTERED INDEX SCAN.

SELECT * FROM MYTABLE WHERE ACCOUNT LIKE '123%'
execution plan shows CLUSTERED INDEX SEEK.

How, why. Why doesn't the optimizer works good for the first query?

Howdy!Can you refraze the question. Can it be built with the query anylzer?|||LEFT is seen by the optimizer as similar to UPPER. In short, the query plan looks at the function result as an unknown value, and thus the table scan.|||LEFT is seen by the optimizer as similar to UPPER. In short, the query plan looks at the function result as an unknown value, and thus the table scan.well, that's pretty stupid of it, eh :)

oh, i don't mean in the general sense, i am forever telling people not to do stuff like

... where year(transdate) = year(getdate())

i mean specifically in the case of the LEFT function|||Can you refraze the question. Can it be built with the query anylzer?

create table mytable (account varchar(10))

go
create clustered index myindex on mytable(account)
go
declare @.v int
set @.v=1
while @.v<9000
begin
insert mytable select 'abcdefgh'
set @.v=@.v+1
end

-- table scan
select * from mytable where left(account,3)='abc'

-- index seek
select * from mytable where account like 'abc%'

drop table mytable|||is there an index on that column at all ?|||It's likely that the scan occurs because left has to retrieve the whole thing while the like only retrieves the first three characters. The clustered index is going to organize that column by varchar physically on the disk, so the like statement will retrieve two indexes and everything in between, versus the left which will have to check every record "in between".

Does that make sense ?

Cheers,
-Kilka|||It's NonSargable

http://www.sql-server-performance.com/sql_server_performance_audit8.asp

Wednesday, March 7, 2012

God Only Knows Why???

CREATE TABLE [__1] (
[n] [int] IDENTITY (1, 1) NOT NULL ,
[a] [decimal](16, 5) NULL
) ON [PRIMARY]
GO

INSERT INTO __1
(a)
VALUES (1.22115)

select * from __1

------------
RESULTS FROM Query Analyzer
------------

(1 row(s) affected)

n a
---- ------
1.00 1.22

(1 row(s) affected)

When I go to the Enterprise Manager and see the data, it appears as

n a
---- ------
1.00 1.22115

I am soooo confused!! Highly appreciating your comments...try inserting 1.22000|||Originally posted by RaedT
CREATE TABLE [__1] (
[n] [int] IDENTITY (1, 1) NOT NULL ,
[a] [decimal](16, 5) NULL
) ON [PRIMARY]
GO

INSERT INTO __1
(a)
VALUES (1.22115)

select * from __1

------------
RESULTS FROM Query Analyzer
------------

(1 row(s) affected)

n a
---- ------
1.00 1.22

(1 row(s) affected)

When I go to the Enterprise Manager and see the data, it appears as

n a
---- ------
1.00 1.22115

I am soooo confused!! Highly appreciating your comments...
it gives right results for me.|||Karolyn:
After iserting 1.22000, nothing changed!
the output is still rounded to 1.22

harshal_in:
Notice the output from the Query Analyzer. The inserted value 1.22115 was rounded to 1.22, I need the Query Analyzer to give me what really exists in the table 1.22115, not 1.22!!

Originally posted by harshal_in
it gives right results for me.|||sorry I've mis-read your pb

it's the same pb as last week !

you must have a property or option in your QA that
rounds up your data

or maybe you don't see it totally... (?)

try

Select '-' + convert(varchar(50),a) + '-' From Table|||CREATE TABLE [__1] (
[n] [int] IDENTITY (1, 1) NOT NULL ,
[a] [decimal](16, 5) NULL
) ON [PRIMARY]
GO

INSERT INTO __1
(a)
VALUES (1.22115)

select 'Value = '+convert(varchar,a) from __1

What does this return ?|||Output:
------------
Value = 1.22115

? What does this mean?

Originally posted by Enigma

CREATE TABLE [__1] (
[n] [int] IDENTITY (1, 1) NOT NULL ,
[a] [decimal](16, 5) NULL
) ON [PRIMARY]
GO

INSERT INTO __1
(a)
VALUES (1.22115)

select 'Value = '+convert(varchar,a) from __1

What does this return ?|||that you don't see the all the numbers of your result

the column in the QA is too narrow
maybe there's an option to adapt the witdht of a column|||Just curious .. whats the version of sql query analyzer are you using ...
I found no option in QA that does rounding off :confused:|||Go see TOOLS-OPTIONS in the QA

in the Result tab there's a number of caracters

(maybe someone that doen't like you set it to 4)|||QA Version: 8.00.760
Max. Characters per column: 256

Note, even the int type value (1) appears as 1.00

Originally posted by Karolyn
Go see TOOLS-OPTIONS in the QA

in the Result tab there's a number of caracters

(maybe someone that doen't like you set it to 4)|||At least you've got the good result in the table...
(Being optimistic)

Check all the options in your databases and in QA|||how are you starting up your query analyzer ?

By clicking on an icon ? The only thing i can think of is that you might be starting up your qa with some configuration options

Check your shortcut properties ... the error might lie there|||I am starting my QA from the EM.

TOOLS=> SQL QA

Originally posted by Enigma
how are you starting up your query analyzer ?

By clicking on an icon ? The only thing i can think of is that you might be starting up your qa with some configuration options

Check your shortcut properties ... the error might lie there|||did you find the round-up-property ??|||I can go ahead of my work, I converted the decimal numbers to varchar, so I can get the results with 5 decimal places, but I am so frustrated and need to know why? I am so curious to know what the problem is.

Originally posted by Karolyn
did you find the round-up-property ??|||If you see BlindMan or Breitt Kaiser online
Ask them !!!|||I get

n a
---- ------
1 1.22115

(1 row(s) affected)

No way an int is decimal(5,2)

I checked the options for the result set and don't see anything...

What collation are you using...(doubt that that's it either)

I don't buy that a column defined like you posted will ever display an identity that way...|||Grasping at straws here, but Karolyn obligates me to respond...

What is your "Use regional settings when outputting currency, number, dates, and times" setting in QA options? (It's in the connections tab.)

If it is on, try setting it to off.

From Books Online:

"Use regional settings when outputting currency, number, dates, and times.
Turning this setting to ON causes the ODBC driver to respect the local client setting when converting numeric, date, time, and currency values to character strings. The conversion is from SQL Server native data types to character strings only. When the setting is OFF, the driver does not convert numeric, date, time, and currency data to character string data using the client locale setting. The conversion setting is only applicable to output conversion and is only visible when currency, numeric, date, or time values are converted to character strings (which is always the case with Query Analyzer). The default for this setting is OFF. "|||It's in

Tools>Options

Menu

Never even thought to look their...

if that's the case...

Why do people mess with ANY settings...I leave'em alone...

God, If I had to remeber what I set...I'd go crazy....

Certainly ups the Mriacle ante.....

as in "God only knows why"|||Blindman .. i believe you have hit the nail on the head ...|||If I did, it's only because it was the last thing that could be suggested!|||I never would have found that in QA. Good job, Blindman.|||Blindman, you deserve millions kisses. You are a superman.
Brett Kaiser: I did not get all what you posted, but I can smell the aggressive way in your reply. Sorry for INCONVENIENCE and thanks anyway.
Thank you all for help, now I can sleep well.|||Originally posted by RaedT
Blindman, you deserve millions kisses. You are a superman.
Brett Kaiser: I did not get all what you posted, but I can smell the aggressive way in your reply. Sorry for INCONVENIENCE and thanks anyway.
Thank you all for help, now I can sleep well.

Whatever...It was a stretch for us to figure out what happend...know why?

Because we never touch that stuff...

But it seems like someone did...why?

My point was exactly that...don't mess with the settings...|||still that agressive tone in your writing...|||I can't believe I got that one. Like I said, you guys had already eliminated everything else.|||Brett Kaiser: Man take a chill pill,
That option is set to ON by default after installation.

Originally posted by Brett Kaiser
Whatever...It was a stretch for us to figure out what happend...know why?

Because we never touch that stuff...

But it seems like someone did...why?

My point was exactly that...don't mess with the settings...|||"That option is set to ON by default after installation."

Really? I don't recall seeing that set to ON before. And I don't recall every changing it.|||RaedT
try and see if there's someone in your entourage
that doesn't like you
and put that option to ON|||That's because it's not....|||If setting that value to ON is somebody's idea of being malicious, they aren't very imaginative. It was probably set by accident, or there was a "reason for it at the time".

Sunday, February 19, 2012

Global Constants

Hi friends,
I have set of 20 to 25 constant values that is used to assign error codes.
These constants are used in multitiple SP's.
How can I define these constants once and then reuse it?
Example
error_code = 1001 for "Invalid Member"
error_code = 1002 for "Invalid Expert"
these error will occur in multiple sp's. In future if I want to change the
error_code, I should change everywhere, instead if I define in a particular
place and then resuse it. It will be more effective.
How to do this.
I should not use a table to define the error_code.
thanks
vanithaYou have to store it in someplace in order to use it ( a table would be
the place place for that, but you could also use a XML / Ini file where
you read from with openquery, but I think the table approach would eb
the best solutions for that)
HTH, Jens Suessmeyer.|||Vanitha
you can define custom errors in sql server with sp_addmessage. The custom
errors starts from 50001. see BOL for topics sp_addmessage,@.@.error,Raiserror
.
You should never define errors below50000 as they are already defined.
SARENA AMMAI
Regards
R.D
"vanitha" wrote:

> Hi friends,
> I have set of 20 to 25 constant values that is used to assign error codes.
> These constants are used in multitiple SP's.
> How can I define these constants once and then reuse it?
> Example
> error_code = 1001 for "Invalid Member"
> error_code = 1002 for "Invalid Expert"
> these error will occur in multiple sp's. In future if I want to change the
> error_code, I should change everywhere, instead if I define in a particula
r
> place and then resuse it. It will be more effective.
> How to do this.
> I should not use a table to define the error_code.
> thanks
> vanitha|||Thanks a lot.
The custom error messages is added, now how will I use it inside SP?
then this method will update the system table Sysmessages, I am not sure
whether I have permission in the production DB to do this?
thanks
"R.D" wrote:
> Vanitha
> you can define custom errors in sql server with sp_addmessage. The custom
> errors starts from 50001. see BOL for topics sp_addmessage,@.@.error,Raiserr
or.
> You should never define errors below50000 as they are already defined.
> SARENA AMMAI
> Regards
> R.D
>
>
> "vanitha" wrote:
>|||Vanitha
if you have added, then you already had permissions on sysmessages.Other
wise ask your DBA to add.
Now you can use @.@.error to return that number and store it immediately to
another variable.
You can also use RAISERROR.
BOL has good material on this.
btw Meeru ekkada nundi post chestunaru!
Regards
R.D
"vanitha" wrote:
> Thanks a lot.
> The custom error messages is added, now how will I use it inside SP?
> then this method will update the system table Sysmessages, I am not sure
> whether I have permission in the production DB to do this?
> thanks
> "R.D" wrote:
>|||if the Messages should be transfered to another server you can use this
script (tested) that will do the work and create a insert script for
the sysmessages:
SELECT 'IF NOT EXISTS (SELECT * FROM master..sysmessages where
error = ' + CAST(sm.error as varchar(10)) + ' and msglangid = ' +
CAST(sm.msglangid as varchar(10)) + ')' + CHAR(13) +
' EXEC sp_addmessage @.msgnum = ' + CAST(error
as varchar(10)) +
' ,@.severity = ' + CAST(severity as
varchar(10)) +
' ,@.msgtext = N''' + replace(description, '''',
''') + '''' +
' ,@.lang = ''' + lg.name + '''' + CHAR(13)+
'GO' + CHAR(13)
FROM master..sysmessages sm
Inner join master..syslanguages lg
ON sm.msglangid = lg.msglangid
HTH, Jens Suessmeyer.

Global Auto Increment Value

Hi ,

In Sybase, there is concept of global autoincrement

The range of default values for a particular database is pn + 1 to p(n + 1), where p is the partition size and n is the value of the public option GLOBAL_DATABASE_ID. For example, if the partition size is 1000 and GLOBAL_DATABASE_ID is set to 3, then the range is from 3001 to 4000

If synchornization is done betrween 2 database . then in server , the new record will be created
The value of increment value would be max value at server +1

For Example
Database id of database(1) is 1

Table A has 3 rows
The values are 1000000001
1000000002
1000000003

This database id of this database(2) is 2
The records in table A in this database 2000000001
2000000002

Then synchronization is performed.
The records from database(2) comes to Database(1)

So the records in Database(1) are

1000000001
1000000002
1000000003
2000000001
2000000002

In sybase , when we insert a new record in Database(1), the new record will be 1000000004

I have transferred this type of sybase database(1) to Sql Server using DTS.

When I create a new record on Sql Server , the new record which is getting inserted is 2000000003. I want the new record to be inserted is 1000000004.

How is it possible..

Thanks in advance

MS SQL does not have any way to do this built in. IDENTITY columns are always unique within the table, not the database.

I have simulated what you are talking about by creating a seperate table with just one field of the global increment number and using that.|||

Create a DatabaseID column in each table with the tinyint data type and create a default constraint for it with the database number for the corresponding database. Create an identity column. Make the primary key a compound of the DatabaseID and the identity column.

SQL Server's approach to uniqueness across replicated databases is to use the uniqueidentifier data type with a default value based on calling newid(). If you care about the database that owns the row you'll have to have some kind of DatabaseID column then too though.

|||

There is no built-in functionality available to recycle old identity values or gaps. You will have to do that yourself. The link below has a solution that can be used to find gaps in sequential numbers and you can use that to get the next id:

http://www.umachandar.com/technical/SQL6x70Scripts/Main67.htm

Note that you will have to perform the appropriate locking depending on your concurrency requirements to get the correct results.