Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Wednesday, March 28, 2012

Numeric data column and insert from ASP.NET

I am trying to insert some values into a table where the column is of the data type "numeric". The insert works fine.Update does not work.

Update BUT_BREAKDOWN_PCT SET BDP_EFFORT_BREAKDOWN_PCT=0.15 WHERE BDP_BREAKDOWN_ID =1 AND BDP_PHASE_ID = 3 AND BDP_START_EFF_DT = '12/31/2004'

BDP_EFFORT_BREAKDOWN_PCT is a numeric column with a size 5 (4,3)

When I do the updatedirectly from QA, it works fine.

I was googling it and read a KB article saying it's a problem with Service Pack of SQL Server 2000. If it is, then the query should not work even from QA...isn't it?

Anyone had this problem before? Please help.

In SQL Server 2000 you can change the data type to Decimal and your problem will go away but in SQL Server 7.0 Numeric was more stable than Decimal from my experience. Hope this helps.|||If it works OK in Query Analyzer (works fine for me, too), and it isnot working in your application, then your application is not sendingthe exact same information.

What results are you seeing? An error message? Unexpected data in theBDP_EFFORT_BREAKDOWN_PCTcolumn? No update at all?

I am suspecting that you are not seeing any update at all, which meansthat your WHERE condition is not being met. And since you seem tohave a datetime column in your WHERE condition, I would guess furtherthat that is where your problem lies. (Datetime columnstrip up a lot of people.)

If you are having difficulty troubleshooting this further, let us see your code and maybe we can point out the problem.

numeric data

This is a really stupid question, but I've never dealt with it before. How
does one insert or update numeric data with commas in it?
col = numeric (6,2)
In an english database, you can simply remove the commas and all is well.
insert into table (col) values (1,200.34)
would be
insert into table (col) values (1200.34)
In some european countries, the comma is what we use for the period. So,
1.200,34 is equal to 1,200.34 in the USA.
but, the following will of course not work, even if you run the command "SET
LANGUAGE 'German'" on the database first.
insert into table (col) values (1.200,34)
How do you get around this issue?
Thanks!select replace(replace('1.200,34', '.', ''), ',', '.')
To get around this problem,
since I have English and French users for my Web pages,
I have two fields for the user to fill when entering Numeric values.
In your example, the user would enter 1200 in 1 field and 34 in the other.
I simply don't accept commas and periods.
Then I format the number before sending in to the database.
"Jon" <rosenberg@.mainstreams.com> wrote in message
news:9a444$42e8eb3b$438dcb39$29441@.ALLTE
L.NET...
> This is a really stupid question, but I've never dealt with it before.
> How does one insert or update numeric data with commas in it?
> col = numeric (6,2)
> In an english database, you can simply remove the commas and all is well.
> insert into table (col) values (1,200.34)
> would be
> insert into table (col) values (1200.34)
> In some european countries, the comma is what we use for the period. So,
> 1.200,34 is equal to 1,200.34 in the USA.
> but, the following will of course not work, even if you run the command
> "SET LANGUAGE 'German'" on the database first.
> insert into table (col) values (1.200,34)
> How do you get around this issue?
> Thanks!
>

Monday, March 26, 2012

Number of Updated Rows

I want to get the number of rows updated by an update statement in a stored procedure. Is there a way to do this?

Example:

Declare @.NumRow int;

set @.NumRow = udpate table set Name = 'John Doe' where ID = 123456789;

print @.NumRow;

The above doesn't work.

use the @.@.ROWCOUNT internal; something like:

declare @.updateRows integer

UPDATE yourTable
SET ...
WHERE ...
SET @.updateRows = @.@.ROWCOUNT


Dave

|||

Oh yea, a hidden gotcha:

You need to be careful and make sure that the @.@.ROWCOUNT internal is used IMMEDIATELY after the update statement so that its value does not change. You may get surprised if you have any steps between your update statement and where you used @.@.ROWCOUNT.


Dave

|||Yeah, @.@.rowcount is very good that way.

Something else you might want to be aware of is that you can output the rows from an update query. This gives you the chance to do all kinds of extra analysis on what's changed - not just the number of rows, but all kinds of other details too.

Have a look through http://msdn2.microsoft.com/en-us/ms177564.aspx to see some of the things you can get up to.

Robsql

Wednesday, March 21, 2012

number of CPUs that are assigned to each NUMA node

Hello,
SQL Server STD edition with sp2 plus cumlative update package 2
os = 2003 enterprise edition 64 bit.
After looking at http://support.microsoft.com/kb/329204
I was wondering how to detect the number of CPUs that are assigned to each
NUMA node.
I have issued the following :
SELECT DISTINCT memory_node_id
FROM sys.dm_os_memory_clerks
with the return of:
Memory_node_id
0
3
1
2
I believe this indicates that hardware NUMA is enabled.
This box has 4 dual core procs.
TIA,Yes, and I believe that relates back to parent_node_id in
sys.dm_os_schedulers
--
Jason Massie
Web: http://statisticsio.com
RSS: http://feeds.feedburner.com/statisticsio
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:A7FB4D85-F710-4CC1-843C-8A8D80D167BB@.microsoft.com...
> Hello,
> SQL Server STD edition with sp2 plus cumlative update package 2
> os = 2003 enterprise edition 64 bit.
> After looking at http://support.microsoft.com/kb/329204
> I was wondering how to detect the number of CPUs that are assigned to each
> NUMA node.
> I have issued the following :
> SELECT DISTINCT memory_node_id
> FROM sys.dm_os_memory_clerks
> with the return of:
> Memory_node_id
> 0
> 3
> 1
> 2
> I believe this indicates that hardware NUMA is enabled.
> This box has 4 dual core procs.
> TIA,sql

Monday, March 12, 2012

nulls in results pane

stupid queston what is the key sequence that lets you insert nulls into
the results pane without making an update query?
Thanks!
Found it Control key + 0
|||Found it Control key + 0

nulls in results pane

stupid queston what is the key sequence that lets you insert nulls into
the results pane without making an update query?
Thanks!Found it Control key + 0|||Found it Control key + 0

nulls in results pane

stupid queston what is the key sequence that lets you insert nulls into
the results pane without making an update query?
Thanks!Found it Control key + 0|||Found it Control key + 0

Friday, March 9, 2012

Nullable foreign keys

In my SQL Server 2005 T-SQL book, it mentions that SQL Server 2005 now allows you to set Foreign Key Update/Delete Rules to "Set Null" and "Set Default". In Management Studio, I only see "No Action" and "Cascade" as options. I wish to have the foreign key field set to null when the Primary key in the other table is deleted. Does anyone know why these options aren't showing up, or what I can do to achieve this result? Thanks.

Al

Hi,

simply navigate to Modify Foreign key, the following screen should come up:

http://www.sqlserver2005.de/SharedFiles/FKSetNull.JPG

HTH, jens Suessmeyer.

http://www.sqlserver2005.de
|||That's what I am talking about. The only options are No Action and Cascade. I am using SQL Server 2005 Express (The one shipped with VS 2005) in my devlopment environment, but I don't see why this feature wouldn't be there.

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
>

Null problem

Hi all ,
I am using MicrosoftSQL 2000 server in Window 2000 Pro.
I have problem update column "SEC_CARRIER" which allow NULL values .
When execute sql below , it did not update SEC_CARRIER column at all .
However if i added some value in the SEC_CARRIER manually then execute
sql below , is ok .
Anyone have any ideas how to solve this problem ? I cannot change the
column to NOT NULL values because it have implemented and live.
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
SEC_CARRIER = CARRIER_NO + '|' + SEC_CARRIER,
DATE_CARD_ISSUE = @.date_card_issue,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
Thanks
Hi
NULL concatenated with a valid string is still NULL.
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
SEC_CARRIER = CARRIER_NO + '|' + ISNULL(SEC_CARRIER, ''),
DATE_CARD_ISSUE = @.date_card_issue,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"weetat" <test@.wavex-tech.com> wrote in message
news:OjkIp6c5FHA.472@.TK2MSFTNGP15.phx.gbl...
> Hi all ,
> I am using MicrosoftSQL 2000 server in Window 2000 Pro.
> I have problem update column "SEC_CARRIER" which allow NULL values .
> When execute sql below , it did not update SEC_CARRIER column at all .
> However if i added some value in the SEC_CARRIER manually then execute
> sql below , is ok .
> Anyone have any ideas how to solve this problem ? I cannot change the
> column to NOT NULL values because it have implemented and live.
> UPDATE ILS_USER_PROFILE
> SET CARRIER_NO = @.carrier_no ,
> SEC_CARRIER = CARRIER_NO + '|' + SEC_CARRIER,
> DATE_CARD_ISSUE = @.date_card_issue,
> CARD_LOST = @.card_lost
> WHERE CARD_LOST ='N'
> AND BARCODE = @.barcode
> Thanks
|||Thanks , the solve it.
However , how to remove "<NULL>" value in the column ? below is my
stored procedure sql :
example : 12357869|90909|<NULL> --> remove <NULL>
CREATE PROCEDURE dbo.update_carrier
@.barcode varchar(14),
@.carrier_no varchar(200),
@.first_activated datetime,
@.card_lost varchar(1)
AS
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
FIRST_ACTIVATED = @.first_activated,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
GO
Thanks
Mike Epprecht (SQL MVP) wrote:
> Hi
> NULL concatenated with a valid string is still NULL.
> UPDATE ILS_USER_PROFILE
> SET CARRIER_NO = @.carrier_no ,
> SEC_CARRIER = CARRIER_NO + '|' + ISNULL(SEC_CARRIER, ''),
> DATE_CARD_ISSUE = @.date_card_issue,
> CARD_LOST = @.card_lost
> WHERE CARD_LOST ='N'
> AND BARCODE = @.barcode
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "weetat" <test@.wavex-tech.com> wrote in message
> news:OjkIp6c5FHA.472@.TK2MSFTNGP15.phx.gbl...
>
>

Monday, February 20, 2012

Null problem

Hi all ,
I am using MicrosoftSQL 2000 server in Window 2000 Pro.
I have problem update column "SEC_CARRIER" which allow NULL values .
When execute sql below , it did not update SEC_CARRIER column at all .
However if i added some value in the SEC_CARRIER manually then execute
sql below , is ok .
Anyone have any ideas how to solve this problem ? I cannot change the
column to NOT NULL values because it have implemented and live.
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
SEC_CARRIER = CARRIER_NO + '|' + SEC_CARRIER,
DATE_CARD_ISSUE = @.date_card_issue,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
ThanksHi
NULL concatenated with a valid string is still NULL.
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
SEC_CARRIER = CARRIER_NO + '|' + ISNULL(SEC_CARRIER, ''),
DATE_CARD_ISSUE = @.date_card_issue,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"weetat" <test@.wavex-tech.com> wrote in message
news:OjkIp6c5FHA.472@.TK2MSFTNGP15.phx.gbl...
> Hi all ,
> I am using MicrosoftSQL 2000 server in Window 2000 Pro.
> I have problem update column "SEC_CARRIER" which allow NULL values .
> When execute sql below , it did not update SEC_CARRIER column at all .
> However if i added some value in the SEC_CARRIER manually then execute
> sql below , is ok .
> Anyone have any ideas how to solve this problem ? I cannot change the
> column to NOT NULL values because it have implemented and live.
> UPDATE ILS_USER_PROFILE
> SET CARRIER_NO = @.carrier_no ,
> SEC_CARRIER = CARRIER_NO + '|' + SEC_CARRIER,
> DATE_CARD_ISSUE = @.date_card_issue,
> CARD_LOST = @.card_lost
> WHERE CARD_LOST ='N'
> AND BARCODE = @.barcode
> Thanks|||Thanks , the solve it.
However , how to remove "<NULL>" value in the column ? below is my
stored procedure sql :
example : 12357869|90909|<NULL> --> remove <NULL>
CREATE PROCEDURE dbo.update_carrier
@.barcode varchar(14),
@.carrier_no varchar(200),
@.first_activated datetime,
@.card_lost varchar(1)
AS
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
FIRST_ACTIVATED = @.first_activated,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
GO
Thanks
Mike Epprecht (SQL MVP) wrote:
> Hi
> NULL concatenated with a valid string is still NULL.
> UPDATE ILS_USER_PROFILE
> SET CARRIER_NO = @.carrier_no ,
> SEC_CARRIER = CARRIER_NO + '|' + ISNULL(SEC_CARRIER, '')
,
> DATE_CARD_ISSUE = @.date_card_issue,
> CARD_LOST = @.card_lost
> WHERE CARD_LOST ='N'
> AND BARCODE = @.barcode
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "weetat" <test@.wavex-tech.com> wrote in message
> news:OjkIp6c5FHA.472@.TK2MSFTNGP15.phx.gbl...
>
>
>

Null problem

Hi all ,
I am using MicrosoftSQL 2000 server in Window 2000 Pro.
I have problem update column "SEC_CARRIER" which allow NULL values .
When execute sql below , it did not update SEC_CARRIER column at all .
However if i added some value in the SEC_CARRIER manually then execute
sql below , is ok .
Anyone have any ideas how to solve this problem ? I cannot change the
column to NOT NULL values because it have implemented and live.
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
SEC_CARRIER = CARRIER_NO + '|' + SEC_CARRIER,
DATE_CARD_ISSUE = @.date_card_issue,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
ThanksHi
NULL concatenated with a valid string is still NULL.
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
SEC_CARRIER = CARRIER_NO + '|' + ISNULL(SEC_CARRIER, ''),
DATE_CARD_ISSUE = @.date_card_issue,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"weetat" <test@.wavex-tech.com> wrote in message
news:OjkIp6c5FHA.472@.TK2MSFTNGP15.phx.gbl...
> Hi all ,
> I am using MicrosoftSQL 2000 server in Window 2000 Pro.
> I have problem update column "SEC_CARRIER" which allow NULL values .
> When execute sql below , it did not update SEC_CARRIER column at all .
> However if i added some value in the SEC_CARRIER manually then execute
> sql below , is ok .
> Anyone have any ideas how to solve this problem ? I cannot change the
> column to NOT NULL values because it have implemented and live.
> UPDATE ILS_USER_PROFILE
> SET CARRIER_NO = @.carrier_no ,
> SEC_CARRIER = CARRIER_NO + '|' + SEC_CARRIER,
> DATE_CARD_ISSUE = @.date_card_issue,
> CARD_LOST = @.card_lost
> WHERE CARD_LOST ='N'
> AND BARCODE = @.barcode
> Thanks|||Thanks , the solve it.
However , how to remove "<NULL>" value in the column ? below is my
stored procedure sql :
example : 12357869|90909|<NULL> --> remove <NULL>
CREATE PROCEDURE dbo.update_carrier
@.barcode varchar(14),
@.carrier_no varchar(200),
@.first_activated datetime,
@.card_lost varchar(1)
AS
UPDATE ILS_USER_PROFILE
SET CARRIER_NO = @.carrier_no ,
FIRST_ACTIVATED = @.first_activated,
CARD_LOST = @.card_lost
WHERE CARD_LOST ='N'
AND BARCODE = @.barcode
GO
Thanks
Mike Epprecht (SQL MVP) wrote:
> Hi
> NULL concatenated with a valid string is still NULL.
> UPDATE ILS_USER_PROFILE
> SET CARRIER_NO = @.carrier_no ,
> SEC_CARRIER = CARRIER_NO + '|' + ISNULL(SEC_CARRIER, ''),
> DATE_CARD_ISSUE = @.date_card_issue,
> CARD_LOST = @.card_lost
> WHERE CARD_LOST ='N'
> AND BARCODE = @.barcode
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "weetat" <test@.wavex-tech.com> wrote in message
> news:OjkIp6c5FHA.472@.TK2MSFTNGP15.phx.gbl...
>>Hi all ,
>> I am using MicrosoftSQL 2000 server in Window 2000 Pro.
>> I have problem update column "SEC_CARRIER" which allow NULL values .
>> When execute sql below , it did not update SEC_CARRIER column at all .
>> However if i added some value in the SEC_CARRIER manually then execute
>>sql below , is ok .
>> Anyone have any ideas how to solve this problem ? I cannot change the
>>column to NOT NULL values because it have implemented and live.
>> UPDATE ILS_USER_PROFILE
>> SET CARRIER_NO = @.carrier_no ,
>> SEC_CARRIER = CARRIER_NO + '|' + SEC_CARRIER,
>> DATE_CARD_ISSUE = @.date_card_issue,
>> CARD_LOST = @.card_lost
>> WHERE CARD_LOST ='N'
>> AND BARCODE = @.barcode
>>Thanks
>
>