Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Wednesday, March 28, 2012

New to Cursors - HELP

My stored proc is below but I have no idea as to why the proc just spins - i
t
runs and never returns - I am assuming I have an infinite look somehow in my
cursor but this is the first SP I've written with a cursor so I'm lost -
Anyone who can point me in the right direction I would be very grateful -
ALSO - is there a way to return to the results screen values at certain
points in a transaction - for example as each row changes can you return a
value to the results screen so you can see that it is doing something at all
?
- No debug authority on the server or I'd do that.
ALTER PROCEDURE dbo.InterrogateRealignRecords AS
/* ----
GO SEE IF THERE ARE ANY CHANGED SHADE
RECORDS FIRST AND RETURN THE COUNT INTO
@.ICOUNTSHDCHGS
---- */
Declare @.numSUCforShade int,@.ICOUNTSHDCHGS int,@.ICOUNTPROPCHGS INT,
@.ICOUNTSUBSEGCHGS INT,@.old_shade_ID Int, @.old_property_ID Int, @.old_subseg_I
D
Int
-- select count(*) from #shades_suc_bu
-- drop table #shades_suc_bu
select Shade_ID, SUC_Code,UPC
into #shades_suc_bu
from shade_Suc
Declare curChangeValues Scroll Cursor For
Select Count(*)
From PPGG_Admin.UPC_Shades_Realigned
Where shade_ID <> old_Shade_ID
Open curChangeValues
Fetch Next From curChangeValues
Into @.iCOUNTSHDCHGS
WHILE (@.@.fetch_status = 0)
BEGIN
if @.ICOUNTSHDCHGS > 0
/* --- */
/* THERE ARE CHANGED SHADE ID'S TO LOOK AT */
/* GO AND GET THE RECORDS SO WE CAN LOOK */
/* AT EACH ONE SEPARATELY */
/* --- */
declare curShadeChngVal scroll cursor for
Select old_Shade_ID, old_property_ID,old_product_Subsegment_I
D
From PPGG_Admin.UPC_Shades_Realigned
Where shade_ID <> old_Shade_ID
Open curShadeChngVal
Fetch Next From curShadeChngVal
Into @.old_shade_ID
,@.old_property_ID
,@.old_subseg_ID
Select @.old_shade_ID
,@.old_property_ID
,@.old_subseg_ID
WHILE (@.@.fetch_status =0)
Begin
/* ---*/
/* DURING THE LOOP CHECK THE SUC TABLE
TO SEE IF ANY UPCS STILL EXIST
FOR THIS SHADE */
/* ---*/
DECLARE curSUCVal scroll cursor for
Select Count(*) from Shade_SUC
where Shade_ID = @.old_Shade_ID
OPEN curSUCVal
fetch next from curSUCVal
into @.numSUCforShade
if @.numSUCforShade > 0
Begin
--declare @.dan int
--set @.dan =1
delete from #shades_suc_bu where Shade_ID = @.old_Shade_ID
end
CLOSE curSUCVal
Deallocate curSUCVal
END
end
Close curChangeValues
Deallocate curChangeValues
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOHEY THANKS - I sufficiently feel like an idiot - not everyone is a guru my
friend. But thanks for your tact. (not)
"CBretana" wrote:
> Entire thing is messed up
> 1) Each time you execute a cursor loop you have to Fetch Next INSIDE THE
> LOOP at the end, or you're just processing the same row over and over..
> 2) Same with cursor curShadeChngVal, there's a Ferch Next just befor the
> While Loop, but no Fetch Next at the end of the While loop to move to the
> nect record...
> 3) you have triply nested cursors and the innermost cursor (curSUCVal) see
ms
> not to be looping at all, (THERE'S NO WHILE LOOP FOR IT !!) you're just
> processing the first row of it...
> So why use cursor curSUCVal at all '
> "Dan" wrote:
>|||Entire thing is messed up
1) Each time you execute a cursor loop you have to Fetch Next INSIDE THE
LOOP at the end, or you're just processing the same row over and over..
2) Same with cursor curShadeChngVal, there's a Ferch Next just befor the
While Loop, but no Fetch Next at the end of the While loop to move to the
nect record...
3) you have triply nested cursors and the innermost cursor (curSUCVal) seems
not to be looping at all, (THERE'S NO WHILE LOOP FOR IT !!) you're just
processing the first row of it...
So why use cursor curSUCVal at all '
"Dan" wrote:

> My stored proc is below but I have no idea as to why the proc just spins -
it
> runs and never returns - I am assuming I have an infinite look somehow in
my
> cursor but this is the first SP I've written with a cursor so I'm lost -
> Anyone who can point me in the right direction I would be very grateful -
> ALSO - is there a way to return to the results screen values at certain
> points in a transaction - for example as each row changes can you return a
> value to the results screen so you can see that it is doing something at a
ll?
> - No debug authority on the server or I'd do that.
> ALTER PROCEDURE dbo.InterrogateRealignRecords AS
> /* ----
> GO SEE IF THERE ARE ANY CHANGED SHADE
> RECORDS FIRST AND RETURN THE COUNT INTO
> @.ICOUNTSHDCHGS
> ---- */
> Declare @.numSUCforShade int,@.ICOUNTSHDCHGS int,@.ICOUNTPROPCHGS INT,
> @.ICOUNTSUBSEGCHGS INT,@.old_shade_ID Int, @.old_property_ID Int, @.old_subseg
_ID
> Int
> -- select count(*) from #shades_suc_bu
> -- drop table #shades_suc_bu
> select Shade_ID, SUC_Code,UPC
> into #shades_suc_bu
> from shade_Suc
> Declare curChangeValues Scroll Cursor For
> Select Count(*)
> From PPGG_Admin.UPC_Shades_Realigned
> Where shade_ID <> old_Shade_ID
> Open curChangeValues
> Fetch Next From curChangeValues
> Into @.iCOUNTSHDCHGS
> WHILE (@.@.fetch_status = 0)
> BEGIN
> if @.ICOUNTSHDCHGS > 0
> /* --- */
> /* THERE ARE CHANGED SHADE ID'S TO LOOK AT */
> /* GO AND GET THE RECORDS SO WE CAN LOOK */
> /* AT EACH ONE SEPARATELY */
> /* --- */
> declare curShadeChngVal scroll cursor for
> Select old_Shade_ID, old_property_ID,old_product_Subsegment_I
D
> From PPGG_Admin.UPC_Shades_Realigned
> Where shade_ID <> old_Shade_ID
> Open curShadeChngVal
> Fetch Next From curShadeChngVal
> Into @.old_shade_ID
> ,@.old_property_ID
> ,@.old_subseg_ID
> Select @.old_shade_ID
> ,@.old_property_ID
> ,@.old_subseg_ID
> WHILE (@.@.fetch_status =0)
> Begin
> /* ---*/
> /* DURING THE LOOP CHECK THE SUC TABLE
> TO SEE IF ANY UPCS STILL EXIST
> FOR THIS SHADE */
> /* ---*/
> DECLARE curSUCVal scroll cursor for
> Select Count(*) from Shade_SUC
> where Shade_ID = @.old_Shade_ID
> OPEN curSUCVal
> fetch next from curSUCVal
> into @.numSUCforShade
> if @.numSUCforShade > 0
> Begin
> --declare @.dan int
> --set @.dan =1
> delete from #shades_suc_bu where Shade_ID = @.old_Shade_ID
> end
> CLOSE curSUCVal
> Deallocate curSUCVal
> END
>
> end
> Close curChangeValues
> Deallocate curChangeValues
>
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
>|||Dan, I Just noticed somethiong else...
the First cursor, curChangeValues is defined on
Select Count(*)
From PPGG_Admin.UPC_Shades_Realigned
Where shade_ID <> old_Shade_ID
This doesn't return a set of records at all, it just returns a single count
of records.. .You use cursors (when there's no other alternative) to ITERAT
E
through a COLLECTION of records when you need t oprocess each one
individually... not simply to get data. I suspect you really need to read a
bit about the basics of SQL.
"Dan" wrote:

> My stored proc is below but I have no idea as to why the proc just spins -
it
> runs and never returns - I am assuming I have an infinite look somehow in
my
> cursor but this is the first SP I've written with a cursor so I'm lost -
> Anyone who can point me in the right direction I would be very grateful -
> ALSO - is there a way to return to the results screen values at certain
> points in a transaction - for example as each row changes can you return a
> value to the results screen so you can see that it is doing something at a
ll?
> - No debug authority on the server or I'd do that.
> ALTER PROCEDURE dbo.InterrogateRealignRecords AS
> /* ----
> GO SEE IF THERE ARE ANY CHANGED SHADE
> RECORDS FIRST AND RETURN THE COUNT INTO
> @.ICOUNTSHDCHGS
> ---- */
> Declare @.numSUCforShade int,@.ICOUNTSHDCHGS int,@.ICOUNTPROPCHGS INT,
> @.ICOUNTSUBSEGCHGS INT,@.old_shade_ID Int, @.old_property_ID Int, @.old_subseg
_ID
> Int
> -- select count(*) from #shades_suc_bu
> -- drop table #shades_suc_bu
> select Shade_ID, SUC_Code,UPC
> into #shades_suc_bu
> from shade_Suc
> Declare curChangeValues Scroll Cursor For
> Select Count(*)
> From PPGG_Admin.UPC_Shades_Realigned
> Where shade_ID <> old_Shade_ID
> Open curChangeValues
> Fetch Next From curChangeValues
> Into @.iCOUNTSHDCHGS
> WHILE (@.@.fetch_status = 0)
> BEGIN
> if @.ICOUNTSHDCHGS > 0
> /* --- */
> /* THERE ARE CHANGED SHADE ID'S TO LOOK AT */
> /* GO AND GET THE RECORDS SO WE CAN LOOK */
> /* AT EACH ONE SEPARATELY */
> /* --- */
> declare curShadeChngVal scroll cursor for
> Select old_Shade_ID, old_property_ID,old_product_Subsegment_I
D
> From PPGG_Admin.UPC_Shades_Realigned
> Where shade_ID <> old_Shade_ID
> Open curShadeChngVal
> Fetch Next From curShadeChngVal
> Into @.old_shade_ID
> ,@.old_property_ID
> ,@.old_subseg_ID
> Select @.old_shade_ID
> ,@.old_property_ID
> ,@.old_subseg_ID
> WHILE (@.@.fetch_status =0)
> Begin
> /* ---*/
> /* DURING THE LOOP CHECK THE SUC TABLE
> TO SEE IF ANY UPCS STILL EXIST
> FOR THIS SHADE */
> /* ---*/
> DECLARE curSUCVal scroll cursor for
> Select Count(*) from Shade_SUC
> where Shade_ID = @.old_Shade_ID
> OPEN curSUCVal
> fetch next from curSUCVal
> into @.numSUCforShade
> if @.numSUCforShade > 0
> Begin
> --declare @.dan int
> --set @.dan =1
> delete from #shades_suc_bu where Shade_ID = @.old_Shade_ID
> end
> CLOSE curSUCVal
> Deallocate curSUCVal
> END
>
> end
> Close curChangeValues
> Deallocate curChangeValues
>
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
>|||Seriously, if you are new to cursors then you should stay away from
them for straight data manipulation stuff. Most of the time there are
better solutions without using cursors so until you are VERY confident
that you have enough SQL expertise to know when a cursor is the right
choice it's best to assume that you don't need them at all.
If you need more help with a solution then please come back with DDL
and sample data so that we can understand your requirements. See:
http://www.aspfaq.com/etiquette.asp?id=5006
David Portas
SQL Server MVP
--|||OK David,
If I am in need of iterating through a row of records to decide on an action
(update, delete, insert new etc) then what other option do I have in a Store
d
Proc?
Thanks
"David Portas" wrote:

> Seriously, if you are new to cursors then you should stay away from
> them for straight data manipulation stuff. Most of the time there are
> better solutions without using cursors so until you are VERY confident
> that you have enough SQL expertise to know when a cursor is the right
> choice it's best to assume that you don't need them at all.
> If you need more help with a solution then please come back with DDL
> and sample data so that we can understand your requirements. See:
> http://www.aspfaq.com/etiquette.asp?id=5006
> --
> David Portas
> SQL Server MVP
> --
>|||Dan,
CAPS not meant to insult, just to emphasize, sorry if tone was rough...
No attempt to insult or denigrate was intended.
And there's a differencve between being intelligence, and education.
EVERYONE (CAPS only to emphasize) is "undeducated" when they begin learning
a
new skill... There's no need to feel offended because you're not yet educate
d
...
From your post, a judgement might be made about your SQL knowledge, but
not about your intelligence. It's what you decide to do next that will
speak to the latter issue !
"Dan" wrote:
> HEY THANKS - I sufficiently feel like an idiot - not everyone is a guru my
> friend. But thanks for your tact. (not)
> "CBretana" wrote:
>|||Maybe a WHERE clause on each of those statements in succession -
probably with EXISTS, but that depends on what you are doing.
UPDATE x
SET ... ?
WHERE EXISTS
(SELECT *
FROM PPGG_Admin.UPC_Shades_Realigne=ADd
WHERE id =3D x.id
AND ... ?)
INSERT INTO z (...)
SELECT ...
FROM PPGG_Admin.UPC_Shades_Realigne=ADd AS T
WHERE NOT EXISTS
(SELECT *
FROM z
WHERE T.id =3D z.id
AND ... ?)
--=20
David Portas
SQL Server MVP
--|||Why do you need to iterate through a collection of records?
It appears from the code you posted the only thing the SP is doing is
deleting selected records from temp table #shades_suc_bu in the line
delete from #shades_suc_bu where Shade_ID = @.old_Shade_ID
Which is sort of pointless because the temp table is not then used for
anything else, and it will dissapear immediately after the SP terminates.
But even if it was doing something, the delete could probably be done in one
SQL statement that properly identified the records that need to be deleted,
instead of using any cursors at all...
But first, what exactly is this SP supposed to be doing ?
"Dan" wrote:
> OK David,
> If I am in need of iterating through a row of records to decide on an acti
on
> (update, delete, insert new etc) then what other option do I have in a Sto
red
> Proc?
> Thanks
> "David Portas" wrote:
>|||Usenet drama....
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:4F63E75A-9565-464A-AA41-36F7F3B46CDA@.microsoft.com...
> My stored proc is below but I have no idea as to why the proc just spins -
it
> runs and never returns - I am assuming I have an infinite look somehow in
my
> cursor but this is the first SP I've written with a cursor so I'm lost -
> Anyone who can point me in the right direction I would be very grateful -
> ALSO - is there a way to return to the results screen values at certain
> points in a transaction - for example as each row changes can you return a
> value to the results screen so you can see that it is doing something at
all?
> - No debug authority on the server or I'd do that.
> ALTER PROCEDURE dbo.InterrogateRealignRecords AS
> /* ----
> GO SEE IF THERE ARE ANY CHANGED SHADE
> RECORDS FIRST AND RETURN THE COUNT INTO
> @.ICOUNTSHDCHGS
> ---- */
> Declare @.numSUCforShade int,@.ICOUNTSHDCHGS int,@.ICOUNTPROPCHGS INT,
> @.ICOUNTSUBSEGCHGS INT,@.old_shade_ID Int, @.old_property_ID Int,
@.old_subseg_ID
> Int
> -- select count(*) from #shades_suc_bu
> -- drop table #shades_suc_bu
> select Shade_ID, SUC_Code,UPC
> into #shades_suc_bu
> from shade_Suc
> Declare curChangeValues Scroll Cursor For
> Select Count(*)
> From PPGG_Admin.UPC_Shades_Realigned
> Where shade_ID <> old_Shade_ID
> Open curChangeValues
> Fetch Next From curChangeValues
> Into @.iCOUNTSHDCHGS
> WHILE (@.@.fetch_status = 0)
> BEGIN
> if @.ICOUNTSHDCHGS > 0
> /* --- */
> /* THERE ARE CHANGED SHADE ID'S TO LOOK AT */
> /* GO AND GET THE RECORDS SO WE CAN LOOK */
> /* AT EACH ONE SEPARATELY */
> /* --- */
> declare curShadeChngVal scroll cursor for
> Select old_Shade_ID, old_property_ID,old_product_Subsegment_I
D
> From PPGG_Admin.UPC_Shades_Realigned
> Where shade_ID <> old_Shade_ID
> Open curShadeChngVal
> Fetch Next From curShadeChngVal
> Into @.old_shade_ID
> ,@.old_property_ID
> ,@.old_subseg_ID
> Select @.old_shade_ID
> ,@.old_property_ID
> ,@.old_subseg_ID
> WHILE (@.@.fetch_status =0)
> Begin
> /* ---*/
> /* DURING THE LOOP CHECK THE SUC TABLE
> TO SEE IF ANY UPCS STILL EXIST
> FOR THIS SHADE */
> /* ---*/
> DECLARE curSUCVal scroll cursor for
> Select Count(*) from Shade_SUC
> where Shade_ID = @.old_Shade_ID
> OPEN curSUCVal
> fetch next from curSUCVal
> into @.numSUCforShade
> if @.numSUCforShade > 0
> Begin
> --declare @.dan int
> --set @.dan =1
> delete from #shades_suc_bu where Shade_ID = @.old_Shade_ID
> end
> CLOSE curSUCVal
> Deallocate curSUCVal
> END
>
> end
> Close curChangeValues
> Deallocate curChangeValues
>
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
>

New Tables and Stored procedures are saving as System Tables

When I try to create a new table/stored procedure, MSDE is saving it as
system table/procedure. And this is happening to all the databases on that
instance.
I checked the sysobjects table. The new tables are saved as Type 'U'.
But their status is in -ve nos.
What I can do to fix that?
Hi
You should not rely on using the "FOR MS USE" objects/columns. What does
OBJECTPROPERTY(id,'IsSystemTable') return?
John
"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:45F7565B-FC35-437E-88CC-30E896875DF0@.microsoft.com...
> When I try to create a new table/stored procedure, MSDE is saving it as
> system table/procedure. And this is happening to all the databases on that
> instance.
> I checked the sysobjects table. The new tables are saved as Type 'U'.
> But their status is in -ve nos.
> What I can do to fix that?
>
>

Monday, March 26, 2012

New Tables and Stored procedures are saving as System Tables

When I try to create a new table/stored procedure, MSDE is saving it as
system table/procedure. And this is happening to all the databases on that
instance.
I checked the sysobjects table. The new tables are saved as Type 'U'.
But their status is in -ve nos.
What I can do to fix that?Hi
You should not rely on using the "FOR MS USE" objects/columns. What does
OBJECTPROPERTY(id,'IsSystemTable') return?
John
"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:45F7565B-FC35-437E-88CC-30E896875DF0@.microsoft.com...
> When I try to create a new table/stored procedure, MSDE is saving it as
> system table/procedure. And this is happening to all the databases on that
> instance.
> I checked the sysobjects table. The new tables are saved as Type 'U'.
> But their status is in -ve nos.
> What I can do to fix that?
>
>

new stored procedures created as type system instead of user

I am running SQL 2000 SP4. When I create a new stored procedure it is
being created as type system instead of user. How can I make it so
every new sp I create is type user instead of system? Thanks in
advance.Hi
"ginarunco@.hotmail.com" wrote:

> I am running SQL 2000 SP4. When I create a new stored procedure it is
> being created as type system instead of user. How can I make it so
> every new sp I create is type user instead of system? Thanks in
> advance.
>
Run DBCC TRACESTATUS ( 1717 )
If the flag is on, run
EXEC sp_MS_upd_sysobj_category 2
Check the SQL Server Startup parameters to make sure it doesn't turn this
trace flag on at startup.
John

new stored procedures created as type system instead of user

I am running SQL 2000 SP4. When I create a new stored procedure it is
being created as type system instead of user. How can I make it so
every new sp I create is type user instead of system? Thanks in
advance.
Hi
"ginarunco@.hotmail.com" wrote:

> I am running SQL 2000 SP4. When I create a new stored procedure it is
> being created as type system instead of user. How can I make it so
> every new sp I create is type user instead of system? Thanks in
> advance.
>
Run DBCC TRACESTATUS ( 1717 )
If the flag is on, run
EXEC sp_MS_upd_sysobj_category 2
Check the SQL Server Startup parameters to make sure it doesn't turn this
trace flag on at startup.
John
sql

new stored procedures created as type system instead of user

I am running SQL 2000 SP4. When I create a new stored procedure it is
being created as type system instead of user. How can I make it so
every new sp I create is type user instead of system? Thanks in
advance.Hi
"ginarunco@.hotmail.com" wrote:
> I am running SQL 2000 SP4. When I create a new stored procedure it is
> being created as type system instead of user. How can I make it so
> every new sp I create is type user instead of system? Thanks in
> advance.
>
Run DBCC TRACESTATUS ( 1717 )
If the flag is on, run
EXEC sp_MS_upd_sysobj_category 2
Check the SQL Server Startup parameters to make sure it doesn't turn this
trace flag on at startup.
John

new stored procedure problem...

using tables with identity columns and trying to create a stored procedure to load records into 2 tables.
here is what i am trying to do. but when i try to save it i get
"Error 8101: An explicit value for the identity column in table 'XAPCHKDETAIL' can only be specified when a column list is used and IDENTITY_INSERT is ON"
Do i have to break this down into 2 SP's or can i do it some how with this one.
Also, how can i get the XAPCHECKS table to only load the DISTINCT values from the APPHISTF. the APPHISTF will possible have multiple check numbers that are the same but i only need that row in the XAPCHECKS table once.

CREATE PROCEDURE isp_ap_load_checks
@.p_comp char(2),
@.p_vend char(6),
@.p_user char(12),
@.p_date1 char(8),
@.p_date2 char(8)
as

if (@.p_user <= '')
begin
set @.p_user = 'system'
end

if (@.p_date1 <= '00000000')
begin
set @.p_date1 = '00000000'
end

if (@.p_date2 <= @.p_date1)
begin
set @.p_date2 = '99999999'
end

delete from XAPCHECKS
where xapck_comp = @.p_comp and xapck_vend = @.p_vend and xapck_user = @.p_user

delete from XAPCHKDETAIL
where xapcd_comp = @.p_comp and xapcd_vend = @.p_vend and xapcd_user = @.p_user

insert into XAPCHECKS
select apph_comp, apph_vend, @.p_user,
max(str(yy,4) + replace(str(mm,2),' ','0') + replace(str(dd,2),' ','0')), apph_payck, chm_type, chm_stat, apt_bank,
apph_paymnts, apph_stat

from APPHISTF LEFT JOIN APTRANF on apt_comp = apph_comp and apt_vend = apph_vend and
apt_type = apph_type and apt_id = apph_id
LEFT JOIN APBANKF ON apb_code = apt_bank
left join CHMASTF on chm_comp = apb_comp and chm_acct = apb_cash and chm_no = apph_payck
where (apph_comp = @.p_comp) and (apph_vend = @.p_vend) and
(apph_payck > 0 and
(str(yy,4) + replace(str(mm,2),' ','0') + replace(str(dd,2),' ','0') > '00000000'))
group by apph_comp, apph_vend, apph_payck, chm_type, chm_stat, apph_paymnts, apph_stat, apph_type, apt_bank, apph_id

insert into XAPCHKDETAIL
select apph_comp, apph_vend, @.p_user, apph_payck, chm_type, chm_stat, apt_bank, apph_type, apph_id

from APPHISTF LEFT JOIN APTRANF on apt_comp = apph_comp and apt_vend = apph_vend and
apt_type = apph_type and apt_id = apph_id
LEFT JOIN APBANKF ON apb_code = apt_bank
left join CHMASTF on chm_comp = apb_comp and chm_acct = apb_cash and chm_no = apph_payck
where (apph_comp = @.p_comp) and (apph_vend = @.p_vend) and
(apph_payck > 0 and
(str(yy,4) + replace(str(mm,2),' ','0') + replace(str(dd,2),' ','0') > '00000000'))
group by apph_comp, apph_vend, apph_payck, chm_type, chm_stat, apph_paymnts, apph_stat, apph_type, apt_bank, apph_id

GOPost the DDL for XAPCHKDETAIL.|||here is the sql script for the table...
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[XAPCHKDETAIL]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[XAPCHKDETAIL]
GO

CREATE TABLE [dbo].[XAPCHKDETAIL] (
[xapcd_comp] [char] (2) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL ,
[xapcd_vend] [char] (6) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL ,
[xapcd_user] [char] (12) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL ,
[xapcd_check] [int] NOT NULL ,
[xapcd_chk_type] [char] (1) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL ,
[xapck_check_status] [char] (1) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL ,
[xapcd_bank] [char] (5) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL ,
[xapcd_type] [char] (1) COLLATE SQL_Latin1_General_CP1_CS_AS NULL ,
[xapcd_id] [char] (18) COLLATE SQL_Latin1_General_CP1_CS_AS NULL ,
[A4GLIdentity] [numeric](9, 0) IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO

CREATE UNIQUE CLUSTERED INDEX [IXAPCHKDETAIL0] ON [dbo].[XAPCHKDETAIL]([xapcd_comp], [xapcd_vend], [xapcd_user], [xapcd_check], [xapcd_chk_type], [xapck_check_status], [xapcd_bank]) ON [PRIMARY]
GO|||Visit http://support.microsoft.com/kb/878501 , an article from Microsoft to resolve the problem.

Cheers,
--Riaz

using tables with identity columns and trying to create a stored procedure to load records into 2 tables.
here is what i am trying to do. but when i try to save it i get
"Error 8101: An explicit value for the identity column in table 'XAPCHKDETAIL' can only be specified when a column list is used and IDENTITY_INSERT is ON"
Do i have to break this down into 2 SP's or can i do it some how with this one.
Also, how can i get the XAPCHECKS table to only load the DISTINCT values from the APPHISTF. the APPHISTF will possible have multiple check numbers that are the same but i only need that row in the XAPCHECKS table once.|||Change this:
insert into XAPCHKDETAIL
select apph_comp, apph_vend, @.p_user, apph_payck, chm_type, chm_stat, apt_bank, apph_type, apph_id
...

...to this:
insert into XAPCHKDETAIL
([xapcd_comp],
[xapcd_vend],
[xapcd_user],
[xapcd_check],
[xapcd_chk_type],
[xapck_check_status],
[xapcd_bank],
[xapcd_type],
[xapcd_id])
select apph_comp, apph_vend, @.p_user, apph_payck, chm_type, chm_stat, apt_bank, apph_type, apph_id
...

ALWAYS enumerate your column names.|||Is there a way that you know of to only load up a distinct record into the XAPCHECKS table. The APPHISTF can have many ID's associated with a single check.
apphistf:
ID 1 check 1
ID 2 check 1
ID 3 check 1
ID 4 check 2
ID 5 check 3
ID 6 check 3
...
what i am trying to accomplish is to get a recap for a vend by check date, check number that doesnt have to tie back to the ID, that is where the XAPCHKDETAIL comes in.|||Either SELECT DISTINCT, or use an aggregate query with MAX or MIN to select one of the IDs to insert.

New stored procedure call


Hi,
Actually the stored procedure ' Update ' is being called when ever I
click new button or edit button . But when i click the save button in the
grid the record is commited. But it is taken care by framework.Now when i
click the save button i must get the message as the record saved.
Thanks,
Jyothsna.Hi Jyothsna
Probably u are using a stored procedure to update the records. Introduce a
return parameter to the stored procedure and return a certain number when th
e
record is sucess and some number when record fails ex. 1 and -1 respectively
try to catch the return value when the button is clicked. Based on the
result display the message.
best Regards,
Chandra
http://chanduas.blogspot.com/
---
"Jyothsna" wrote:

>
> Hi,
> Actually the stored procedure ' Update ' is being called when ever
I
> click new button or edit button . But when i click the save button in the
> grid the record is commited. But it is taken care by framework.Now when i
> click the save button i must get the message as the record saved.
> Thanks,
> Jyothsna.
>
>

Wednesday, March 21, 2012

New session inside SP?

Hi:
I want to open a new session/connection inside the execution of a stored procedure. Is this possible ?
I ask this because I need a new sesssion with its own transaction.
Thanks,
Rui FerreiraThere are ways to do this, but none of them are pretty. They all involve breaking at least one of the fundamental rules about transaction managment.

Can you explain what you are trying to do in more detail? If I knew more about what you wanted, I could give you a clearer, simpler answer than trying to list all of the methods with their pros and cons for you to sort through!

-PatP|||xp_cmdshell, osql will creat their own spid...

Mostly they've been a royal pain in the donkey....|||xp_cmdshell, osql will creat their own spid...

Mostly they've been a royal pain in the donkey....Yeah, that too.

Just from a security standpoint, the OLE objects are much better. The problem with all of the solutions to this kind of problem is that they have so many caveats and potential "tiger trap" situations embedded in them that there isn't a simple answer.

-PatP|||There are ways to do this, but none of them are pretty. They all involve breaking at least one of the fundamental rules about transaction managment.

Can you explain what you are trying to do in more detail? If I knew more about what you wanted, I could give you a clearer, simpler answer than trying to list all of the methods with their pros and cons for you to sort through!

-PatP

I have a stored procedure that generates sequential IDs based on an auxiliar table. I want to include this SP in its own transaction to avoid concurrency problems I'm having now. When one transaction that uses the SP lasts a little longer the table is locked too much time.
I hope my explanation helps...

Thanks,
Rui Ferreira|||What sort of concurrency problems are you having? This sounds like a bad thing to me to try to sidestep any concurrency issues, because if they are causing problems now I think that side-stepping them will cause even bigger problems.

-PatP|||Sounds like the original design is the bigger problem...

Want to show us some code?

Monday, March 12, 2012

New project - thinking of using Visual studio 2005

Hi
I've been developing sql server stored procedures for what seems forever,
right now I just use query analyzer.
I have a new project, and just for a chuckle I'm thinking of using Visual
Studio 2005 for my IDE instead of query analyzer, I'm still pretty much just
going to be creating sql server stored procedures (SQL 2K).
Does anybody have any hints, gotcha's or guidance on whether this is a good
idea, and if so any tips?
I've played around, and one thing I can't find, can I run a SQL and have a
nice output to grid option, like with query analyzer?
The main reason I want to use this, is for being able to put all my sql in a
project, and the integration with sourcesafe.
Thanks in advanceInstead of the 'full' Visual Studio, use the Sql Server Management Studio.
When you disable the 'Summary' tab at startup, it behaves more or less the
same way as ye olde QA, but a little better :)
Yes, you can still have grids and text output :)
Peter
"..." <...@.nowhere.com> wrote in message
news:ehgLtTgQGHA.4896@.TK2MSFTNGP10.phx.gbl...
> Hi
> I've been developing sql server stored procedures for what seems forever,
> right now I just use query analyzer.
> I have a new project, and just for a chuckle I'm thinking of using Visual
> Studio 2005 for my IDE instead of query analyzer, I'm still pretty much
> just going to be creating sql server stored procedures (SQL 2K).
> Does anybody have any hints, gotcha's or guidance on whether this is a
> good idea, and if so any tips?
> I've played around, and one thing I can't find, can I run a SQL and have a
> nice output to grid option, like with query analyzer?
> The main reason I want to use this, is for being able to put all my sql in
> a project, and the integration with sourcesafe.
> Thanks in advance
>|||There is more flexibility within visual studio itself wrt managing your
project (you can add more folders for managing DDL/DML scripts and such).
Typically I manage my project and the source control integration from within
VS and jump back and forth to management studio depending on the specific
task at hand (say building up and testing a specific set of queries within a
larger procedure). SQL management studio allows for source control
integration and projects but is slightly different. The overall impression
I
have gotten from the two is that the SQL management studio projects are
geared more toward DBA work where as VS is more for the DB developer.
HTH
--Tony
"Rogas69" wrote:

> Instead of the 'full' Visual Studio, use the Sql Server Management Studio.
> When you disable the 'Summary' tab at startup, it behaves more or less the
> same way as ye olde QA, but a little better :)
> Yes, you can still have grids and text output :)
> Peter
> "..." <...@.nowhere.com> wrote in message
> news:ehgLtTgQGHA.4896@.TK2MSFTNGP10.phx.gbl...
>
>

Friday, March 9, 2012

New lines in textarea

I need to be able to strip out newline characters from data stored in a
textarea, but I've been unable to locate data so far that tells me how
newlines/carriage returns are stored in SQL Server. Any help on this
is greatly appreciated.CHAR(13)+CHAR(10)
http://www.aspfaq.com/2188
<Joiey.Seeley@.gmail.com> wrote in message
news:1131462555.249672.14910@.g47g2000cwa.googlegroups.com...
>I need to be able to strip out newline characters from data stored in a
> textarea, but I've been unable to locate data so far that tells me how
> newlines/carriage returns are stored in SQL Server. Any help on this
> is greatly appreciated.
>|||You can run the following statements to remove CRLFs from a column within a
table
update testtable set col1 = REPLACE ( col1 , char(10) , '' )
update testtable set col1 = REPLACE ( col1 , char(13) , '' )
testtable is your table and col1 is the column you want to do the replace on
.
Hope this helps
--
Adam J Warne, MCDBA
"Joiey.Seeley@.gmail.com" wrote:

> I need to be able to strip out newline characters from data stored in a
> textarea, but I've been unable to locate data so far that tells me how
> newlines/carriage returns are stored in SQL Server. Any help on this
> is greatly appreciated.
>|||I tried to use this method on a TEXT field using the following:
update support_incident set problem = REPLACE ( problem , char(10) , '' )
update support_incident set col1 = REPLACE ( problem , char(13) , '' )
Got this error message:
Server: Msg 8116, Level 16, State 1, Line 1
Argument data type text is invalid for argument 1 of replace function.
Server: Msg 8116, Level 16, State 1, Line 2
Argument data type text is invalid for argument 1 of replace function.
--
Ray
How do you remove the CRLFs from a text field?
"Adam Warne" wrote:
> You can run the following statements to remove CRLFs from a column within
a
> table
> update testtable set col1 = REPLACE ( col1 , char(10) , '' )
> update testtable set col1 = REPLACE ( col1 , char(13) , '' )
> testtable is your table and col1 is the column you want to do the replace
on.
> Hope this helps
> --
> Adam J Warne, MCDBA
>
> "Joiey.Seeley@.gmail.com" wrote:
>|||http://www.aspfaq.com/2445
"Ray" <ray.smith@.loislaw.com> wrote in message
news:E1FD569C-3F54-42FB-8B45-8C28B04883A5@.microsoft.com...
>I tried to use this method on a TEXT field using the following:
> update support_incident set problem = REPLACE ( problem , char(10) , '' )
> update support_incident set col1 = REPLACE ( problem , char(13) , '' )
> Got this error message:
> Server: Msg 8116, Level 16, State 1, Line 1
> Argument data type text is invalid for argument 1 of replace function.
> Server: Msg 8116, Level 16, State 1, Line 2
> Argument data type text is invalid for argument 1 of replace function.
> --
> Ray
> How do you remove the CRLFs from a text field?
> "Adam Warne" wrote:
>