Showing posts with label type. Show all posts
Showing posts with label type. Show all posts

Tuesday, March 27, 2012

adding a new line

Hello,

I have a column in my table that is ntext data type and it has html data. I need to strip all the html tags, which is pretty easy to do, but I also need to add a new line for every instance of "

". Do any of you know of a function or anything else that does that?

<p style="margin: 0px">11/21/06 - Position closed and filled by competition.

<p style="margin: 0px">&nbsp;

<p style="margin: 0px">11/3/2006 ADDITIONAL RESUMES NEEDED. HEAVY UNIX/LINUX Update 9/15/06 - Manager is still looking for qualified candidates for this position. Please respond NEW POSITION FOR ETS Location: Princeton, NJ Duration: 6 months New Max Rate: $55.00 Recruiter: Steve McDowell


If you are using SQL Server 2005 then convert the column to nvarchar(max). You can then use any of the built-in string functions to replace the values. However, these are operations that is not meant for SQL Server. It is more appropriate to clean the data on the client side before saving it to the database. If you are using SQL Server 2000 then you can use PATINDEX to search for string

and replace it. Below are some scripts that will help.

http://www.umachandar.com/technical/SQL6x70Scripts/Main62.htm -- strips html tags from varchar field. You have to modify it a bit to use it with ntext

http://www.umachandar.com/technical/SQL6x70Scripts/Main53.htm -- shows how to use updatetext

|||

Hello Uma,

First of, Thanks for your help!

I went through the code and I still dont understand how the code will add a new line for

or <n></n> instances. When you look at the data using IE you will see the columns appears like this:

11/21/06 - Position closed and filled by competition.

11/3/2006 ADDITIONAL RESUMES NEEDED. HEAVY UNIX/LINUX Update 9/15/06 - Manager is still looking for qualified candidates for this position.

But in my table you see the column appears with all the html tags and comes out like this:

<p style="margin: 0px">11/21/06 - Position closed and filled by competition.

<p style="margin: 0px">&nbsp;

<p style="margin: 0px">11/3/2006 ADDITIONAL RESUMES NEEDED. HEAVY UNIX/LINUX Update 9/15/06 - Manager is still looking for qualified candidates for this position.

I need to clean up the data and make it appear as simple text in my table without all the html tags but when that column (the new col) is view using IE, it needs to still show the new line for every

or <n></n>.

Can you help? Please let me know if you have any questions.

Adding a new column of a UDT type fails on "invalid data type"

Hi all,

A strange thing happened to me a few days ago - I tried to modify a table, using the SQL server 2005 management studio, in order to add a new column to an existing table. I've entered the column's name and selected one of my UDTs for the column type. When I pressed "enter", I got the following message "invalid data type" !

Needless to say that shouldn't have happen, didn't happen it the previous version (CTP) and for some reason it works on other computers having the same version !

BTW, the database is sql server 2000.

Any ideas what this works on other computers but not on mine ?

Should I re-install the SQL server ? or the framework ?

Thanks,

Ido.

I'm still getting the error - currently on 2 out of 3 computers.

Any ideas ?

Ido.

sql

Adding A Multivalue Parameter

I've got a simple report built that retrieves data based on a serial
number assign to each record. The user has to type the serial number
into the box to run the report. Now I would like to add another
parameter in which they can run the report based on either a date/time
stamp (Start - End) and/or a multivalue parameter from another field
in each record. Do I need to create a new dataset to add these
features to the report ? I've tried adding the multivalue parameter
but either get an error or the drop down is empty.
Thank-you
JeffOn Feb 5, 4:04 pm, jsvi...@.gmail.com wrote:
> I've got a simple report built that retrieves data based on a serial
> number assign to each record. The user has to type the serial number
> into the box to run the report. Now I would like to add another
> parameter in which they can run the report based on either a date/time
> stamp (Start - End) and/or a multivalue parameter from another field
> in each record. Do I need to create a new dataset to add these
> features to the report ? I've tried adding the multivalue parameter
> but either get an error or the drop down is empty.
> Thank-you
> Jeff
If the original dataset is based on a serial number parameter/etc that
always has a value/default value, you should be ok. Of course, you
will want to have this multivalue parameter as the second parameter in
the list (behind the parameter it is dependent on). If this does not
work, then you might want to try adding an additional dataset as you
mentioned. Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||On Feb 5, 8:41=A0pm, EMartinez <emartinez...@.gmail.com> wrote:
> On Feb 5, 4:04 pm, jsvi...@.gmail.com wrote:
> > I've got a simple report built that retrieves data based on a serial
> > number assign to each record. The user has to type the serial number
> > into the box to run the report. Now I would like to add another
> > parameter in which they can run the report based on either a date/time
> > stamp (Start - End) and/or a multivalue parameter from another field
> > in each record. Do I need to create a new dataset to add these
> > features to the report ? I've tried adding the multivalue parameter
> > but either get an error or the drop down is empty.
> > Thank-you
> > Jeff
> If the original dataset is based on a serial number parameter/etc that
> always has a value/default value, you should be ok. Of course, you
> will want to have this multivalue parameter as the second parameter in
> the list (behind the parameter it is dependent on). If this does not
> work, then you might want to try adding an additional dataset as you
> mentioned. Hope this helps.
> Regards,
> Enrique Martinez
> Sr. Software Consultant
I would like to be able to use each parameter independently or
together if possible. Here is the report query that I started with:
SELECT SpindleName AS Tool, Timestamp AS [Date-Time], Accept,
FinalAngle AS Angle, PartId AS CSN, CycleStatus AS Status, PeakTorque
AS Torque
FROM Readings
WHERE (PartId =3D @.PartId)
ORDER BY CSN DESC
The user types the CSN number in a gets a report showing the data for
every tool. I'd like to allow them to run the report based on
selecting one or more specific tools with or without a dependancy on
the CSN number. Is this possible ?
Thanks
Jeff

Saturday, February 25, 2012

Add Identity Column to Table Type UDF

Using SQL 2000 I have the following UDF that returns a table of hierarchical
info from an adjacency list. Is is possible to add an identity column to
@.retFindComponents or otherwise sort the table in the order of the hierarchy
ie root first, followed by descendents?
Thanks, Tad
CREATE FUNCTION dbo.Get_Component_Parts_From_Assembly_Part(@.Root_I D
int,@.IncludeRoot bit)
RETURNS @.retFindComponents TABLE(
Part_Assembly_ID int,
Part_Component_ID int,
Part_Component_Number nvarchar(50),
Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
)
AS
BEGIN
IF (@.IncludeRoot=1)
BEGIN
INSERT INTO @.retFindComponents
SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
Part_id = @.root_id
END
DECLARE
@.Part_Component_ID int,
@.Part_Assembly_ID int,
@.Part_Component_Number nvarchar(50),
@.Part_Component_Type nchar(4)
DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
FROM Parts_Usage u
INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
WHERE Part_Assembly_ID=@.Root_ID
OPEN RetrieveComponents
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
@.Part_Component_Type
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
INSERT INTO @.retFindComponents
SELECT * FROM
dbo.Get_Component_Parts_From_Assembly_Part(@.Part_C omponent_ID,0)
INSERT INTO @.retFindComponents
VALUES(@.Part_Assembly_ID,@.Part_Component_ID,@.Part_ Component_Number,@.Part_Component_Type)
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID,
@.Part_Component_Number,@.Part_Component_Type
END
CLOSE RetrieveComponents
DEALLOCATE RetrieveComponents
RETURN
END
I think I found a solution but it took some reworking. I added an identity
column to the table @.retFindComponents and then changed the INSERT INTO
statements to use explicit column names to avoid conflicting with the
identity column. Because the function is applied recursively it appears that
the leaf nodes in the hierarchy are inserted first and the internal nodes
that branch off the root are added last. Therefore I moved the optional
INSERT INTO statement for @.IncludeRoot=1 to the end of the function. The
resulting table returned by the function is now in an order although I have
to sort by descending ID to get a top-to-bottom view of the hierarchy.
Tad
CREATE FUNCTION dbo.Get_Component_Parts_From_Assembly_Part(@.Root_I D
int,@.IncludeRoot bit)
RETURNS @.retFindComponents TABLE(
ID int identity(1,1),
Part_Assembly_ID int,
Part_Component_ID int,
Part_Component_Number nvarchar(50),
Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
)
AS
BEGIN
DECLARE
@.Part_Component_ID int,
@.Part_Assembly_ID int,
@.Part_Component_Number nvarchar(50),
@.Part_Component_Type nchar(4)
DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
FROM Parts_Usage u
INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
WHERE Part_Assembly_ID=@.Root_ID
OPEN RetrieveComponents
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
@.Part_Component_Type
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
INSERT INTO @.retFindComponents
SELECT Part_Assembly_ID, Part_Component_ID, Part_Component_Number,
Part_Component_Type FROM
dbo.Get_Component_Parts_From_Assembly_Part(@.Part_C omponent_ID,0)
INSERT INTO @.retFindComponents
VALUES(@.Part_Assembly_ID,@.Part_Component_ID,@.Part_ Component_Number,@.Part_Component_Type)
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID,
@.Part_Component_Number,@.Part_Component_Type
END
IF (@.IncludeRoot=1)
BEGIN
INSERT INTO @.retFindComponents (Part_Assembly_ID, Part_Component_ID,
Part_Component_Number, Part_Component_Type)
SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
Part_id = @.root_id
END
CLOSE RetrieveComponents
DEALLOCATE RetrieveComponents
RETURN
END
"Tadwick" wrote:

> Using SQL 2000 I have the following UDF that returns a table of hierarchical
> info from an adjacency list. Is is possible to add an identity column to
> @.retFindComponents or otherwise sort the table in the order of the hierarchy
> ie root first, followed by descendents?
> Thanks, Tad
> CREATE FUNCTION dbo.Get_Component_Parts_From_Assembly_Part(@.Root_I D
> int,@.IncludeRoot bit)
> RETURNS @.retFindComponents TABLE(
> Part_Assembly_ID int,
> Part_Component_ID int,
> Part_Component_Number nvarchar(50),
> Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
> )
> AS
> BEGIN
> IF (@.IncludeRoot=1)
> BEGIN
> INSERT INTO @.retFindComponents
> SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
> Part_id = @.root_id
> END
> DECLARE
> @.Part_Component_ID int,
> @.Part_Assembly_ID int,
> @.Part_Component_Number nvarchar(50),
> @.Part_Component_Type nchar(4)
> DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
> SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
> FROM Parts_Usage u
> INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
> WHERE Part_Assembly_ID=@.Root_ID
> OPEN RetrieveComponents
> FETCH NEXT FROM RetrieveComponents
> INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
> @.Part_Component_Type
> WHILE (@.@.FETCH_STATUS = 0)
> BEGIN
> INSERT INTO @.retFindComponents
> SELECT * FROM
> dbo.Get_Component_Parts_From_Assembly_Part(@.Part_C omponent_ID,0)
> INSERT INTO @.retFindComponents
> VALUES(@.Part_Assembly_ID,@.Part_Component_ID,@.Part_ Component_Number,@.Part_Component_Type)
> FETCH NEXT FROM RetrieveComponents
> INTO @.Part_Assembly_ID, @.Part_Component_ID,
> @.Part_Component_Number,@.Part_Component_Type
> END
> CLOSE RetrieveComponents
> DEALLOCATE RetrieveComponents
> RETURN
> END
>

Add Identity Column to Table Type UDF

Using SQL 2000 I have the following UDF that returns a table of hierarchical
info from an adjacency list. Is is possible to add an identity column to
@.retFindComponents or otherwise sort the table in the order of the hierarchy
ie root first, followed by descendents?
Thanks, Tad
CREATE FUNCTION dbo.Get_Component_Parts_From_Assembly_Part(@.Root_ID
int,@.IncludeRoot bit)
RETURNS @.retFindComponents TABLE(
Part_Assembly_ID int,
Part_Component_ID int,
Part_Component_Number nvarchar(50),
Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
)
AS
BEGIN
IF (@.IncludeRoot=1)
BEGIN
INSERT INTO @.retFindComponents
SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
Part_id = @.root_id
END
DECLARE
@.Part_Component_ID int,
@.Part_Assembly_ID int,
@.Part_Component_Number nvarchar(50),
@.Part_Component_Type nchar(4)
DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
FROM Parts_Usage u
INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
WHERE Part_Assembly_ID=@.Root_ID
OPEN RetrieveComponents
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
@.Part_Component_Type
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
INSERT INTO @.retFindComponents
SELECT * FROM
dbo.Get_Component_Parts_From_Assembly_Part(@.Part_Component_ID,0)
INSERT INTO @.retFindComponent
VALUES(@.Part_Assembly_ID,@.Part_Component_ID,@.Part_Component_Number,@.Part_Component_Type)
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID,
@.Part_Component_Number,@.Part_Component_Type
END
CLOSE RetrieveComponents
DEALLOCATE RetrieveComponents
RETURN
ENDI think I found a solution but it took some reworking. I added an identity
column to the table @.retFindComponents and then changed the INSERT INTO
statements to use explicit column names to avoid conflicting with the
identity column. Because the function is applied recursively it appears that
the leaf nodes in the hierarchy are inserted first and the internal nodes
that branch off the root are added last. Therefore I moved the optional
INSERT INTO statement for @.IncludeRoot=1 to the end of the function. The
resulting table returned by the function is now in an order although I have
to sort by descending ID to get a top-to-bottom view of the hierarchy.
Tad
CREATE FUNCTION dbo.Get_Component_Parts_From_Assembly_Part(@.Root_ID
int,@.IncludeRoot bit)
RETURNS @.retFindComponents TABLE(
ID int identity(1,1),
Part_Assembly_ID int,
Part_Component_ID int,
Part_Component_Number nvarchar(50),
Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
)
AS
BEGIN
DECLARE
@.Part_Component_ID int,
@.Part_Assembly_ID int,
@.Part_Component_Number nvarchar(50),
@.Part_Component_Type nchar(4)
DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
FROM Parts_Usage u
INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
WHERE Part_Assembly_ID=@.Root_ID
OPEN RetrieveComponents
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
@.Part_Component_Type
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
INSERT INTO @.retFindComponents
SELECT Part_Assembly_ID, Part_Component_ID, Part_Component_Number,
Part_Component_Type FROM
dbo.Get_Component_Parts_From_Assembly_Part(@.Part_Component_ID,0)
INSERT INTO @.retFindComponent
VALUES(@.Part_Assembly_ID,@.Part_Component_ID,@.Part_Component_Number,@.Part_Component_Type)
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID,
@.Part_Component_Number,@.Part_Component_Type
END
IF (@.IncludeRoot=1)
BEGIN
INSERT INTO @.retFindComponents (Part_Assembly_ID, Part_Component_ID,
Part_Component_Number, Part_Component_Type)
SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
Part_id = @.root_id
END
CLOSE RetrieveComponents
DEALLOCATE RetrieveComponents
RETURN
END
"Tadwick" wrote:
> Using SQL 2000 I have the following UDF that returns a table of hierarchical
> info from an adjacency list. Is is possible to add an identity column to
> @.retFindComponents or otherwise sort the table in the order of the hierarchy
> ie root first, followed by descendents?
> Thanks, Tad
> CREATE FUNCTION dbo.Get_Component_Parts_From_Assembly_Part(@.Root_ID
> int,@.IncludeRoot bit)
> RETURNS @.retFindComponents TABLE(
> Part_Assembly_ID int,
> Part_Component_ID int,
> Part_Component_Number nvarchar(50),
> Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
> )
> AS
> BEGIN
> IF (@.IncludeRoot=1)
> BEGIN
> INSERT INTO @.retFindComponents
> SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
> Part_id = @.root_id
> END
> DECLARE
> @.Part_Component_ID int,
> @.Part_Assembly_ID int,
> @.Part_Component_Number nvarchar(50),
> @.Part_Component_Type nchar(4)
> DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
> SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
> FROM Parts_Usage u
> INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
> WHERE Part_Assembly_ID=@.Root_ID
> OPEN RetrieveComponents
> FETCH NEXT FROM RetrieveComponents
> INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
> @.Part_Component_Type
> WHILE (@.@.FETCH_STATUS = 0)
> BEGIN
> INSERT INTO @.retFindComponents
> SELECT * FROM
> dbo.Get_Component_Parts_From_Assembly_Part(@.Part_Component_ID,0)
> INSERT INTO @.retFindComponents
> VALUES(@.Part_Assembly_ID,@.Part_Component_ID,@.Part_Component_Number,@.Part_Component_Type)
> FETCH NEXT FROM RetrieveComponents
> INTO @.Part_Assembly_ID, @.Part_Component_ID,
> @.Part_Component_Number,@.Part_Component_Type
> END
> CLOSE RetrieveComponents
> DEALLOCATE RetrieveComponents
> RETURN
> END
>

Add Identity Column to Table Type UDF

Using SQL 2000 I have the following UDF that returns a table of hierarchical
info from an adjacency list. Is is possible to add an identity column to
@.retFindComponents or otherwise sort the table in the order of the hierarchy
ie root first, followed by descendents?
Thanks, Tad
CREATE FUNCTION dbo. Get_Component_Parts_From_Assembly_Part(@.
Root_ID
int,@.IncludeRoot bit)
RETURNS @.retFindComponents TABLE(
Part_Assembly_ID int,
Part_Component_ID int,
Part_Component_Number nvarchar(50),
Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
)
AS
BEGIN
IF (@.IncludeRoot=1)
BEGIN
INSERT INTO @.retFindComponents
SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
Part_id = @.root_id
END
DECLARE
@.Part_Component_ID int,
@.Part_Assembly_ID int,
@.Part_Component_Number nvarchar(50),
@.Part_Component_Type nchar(4)
DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
FROM Parts_Usage u
INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
WHERE Part_Assembly_ID=@.Root_ID
OPEN RetrieveComponents
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
@.Part_Component_Type
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
INSERT INTO @.retFindComponents
SELECT * FROM
dbo. Get_Component_Parts_From_Assembly_Part(@.
Part_Component_ID,0)
INSERT INTO @.retFindComponents
VALUES(@.Part_Assembly_ID,@.Part_Component
_ID,@.Part_Component_Number,@.Part_Com
ponent_Type)
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID,
@.Part_Component_Number,@.Part_Component_T
ype
END
CLOSE RetrieveComponents
DEALLOCATE RetrieveComponents
RETURN
ENDI think I found a solution but it took some reworking. I added an identity
column to the table @.retFindComponents and then changed the INSERT INTO
statements to use explicit column names to avoid conflicting with the
identity column. Because the function is applied recursively it appears tha
t
the leaf nodes in the hierarchy are inserted first and the internal nodes
that branch off the root are added last. Therefore I moved the optional
INSERT INTO statement for @.IncludeRoot=1 to the end of the function. The
resulting table returned by the function is now in an order although I have
to sort by descending ID to get a top-to-bottom view of the hierarchy.
Tad
CREATE FUNCTION dbo. Get_Component_Parts_From_Assembly_Part(@.
Root_ID
int,@.IncludeRoot bit)
RETURNS @.retFindComponents TABLE(
ID int identity(1,1),
Part_Assembly_ID int,
Part_Component_ID int,
Part_Component_Number nvarchar(50),
Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
)
AS
BEGIN
DECLARE
@.Part_Component_ID int,
@.Part_Assembly_ID int,
@.Part_Component_Number nvarchar(50),
@.Part_Component_Type nchar(4)
DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Type
FROM Parts_Usage u
INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
WHERE Part_Assembly_ID=@.Root_ID
OPEN RetrieveComponents
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
@.Part_Component_Type
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
INSERT INTO @.retFindComponents
SELECT Part_Assembly_ID, Part_Component_ID, Part_Component_Number,
Part_Component_Type FROM
dbo. Get_Component_Parts_From_Assembly_Part(@.
Part_Component_ID,0)
INSERT INTO @.retFindComponents
VALUES(@.Part_Assembly_ID,@.Part_Component
_ID,@.Part_Component_Number,@.Part_Com
ponent_Type)
FETCH NEXT FROM RetrieveComponents
INTO @.Part_Assembly_ID, @.Part_Component_ID,
@.Part_Component_Number,@.Part_Component_T
ype
END
IF (@.IncludeRoot=1)
BEGIN
INSERT INTO @.retFindComponents (Part_Assembly_ID, Part_Component_ID,
Part_Component_Number, Part_Component_Type)
SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
Part_id = @.root_id
END
CLOSE RetrieveComponents
DEALLOCATE RetrieveComponents
RETURN
END
"Tadwick" wrote:

> Using SQL 2000 I have the following UDF that returns a table of hierarchic
al
> info from an adjacency list. Is is possible to add an identity column to
> @.retFindComponents or otherwise sort the table in the order of the hierarc
hy
> ie root first, followed by descendents?
> Thanks, Tad
> CREATE FUNCTION dbo. Get_Component_Parts_From_Assembly_Part(@.
Root_ID
> int,@.IncludeRoot bit)
> RETURNS @.retFindComponents TABLE(
> Part_Assembly_ID int,
> Part_Component_ID int,
> Part_Component_Number nvarchar(50),
> Part_Component_Type nchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
> )
> AS
> BEGIN
> IF (@.IncludeRoot=1)
> BEGIN
> INSERT INTO @.retFindComponents
> SELECT NULL, @.root_id, m.Part_Number,m.Part_Type FROM Parts m WHERE
> Part_id = @.root_id
> END
> DECLARE
> @.Part_Component_ID int,
> @.Part_Assembly_ID int,
> @.Part_Component_Number nvarchar(50),
> @.Part_Component_Type nchar(4)
> DECLARE RetrieveComponents CURSOR STATIC LOCAL FOR
> SELECT u.Part_Assembly_ID, u.Part_Component_ID, m.Part_Number, m.Part_Typ
e
> FROM Parts_Usage u
> INNER JOIN Parts m on m.Part_ID = u.Part_Component_ID
> WHERE Part_Assembly_ID=@.Root_ID
> OPEN RetrieveComponents
> FETCH NEXT FROM RetrieveComponents
> INTO @.Part_Assembly_ID, @.Part_Component_ID, @.Part_Component_Number,
> @.Part_Component_Type
> WHILE (@.@.FETCH_STATUS = 0)
> BEGIN
> INSERT INTO @.retFindComponents
> SELECT * FROM
> dbo. Get_Component_Parts_From_Assembly_Part(@.
Part_Component_ID,0)
> INSERT INTO @.retFindComponents
> VALUES(@.Part_Assembly_ID,@.Part_Compone
nt_ID,@.Part_Component_Number,@.Part
_Component_Type)
> FETCH NEXT FROM RetrieveComponents
> INTO @.Part_Assembly_ID, @.Part_Component_ID,
> @.Part_Component_Number,@.Part_Component_T
ype
> END
> CLOSE RetrieveComponents
> DEALLOCATE RetrieveComponents
> RETURN
> END
>

Monday, February 13, 2012

add a column default value from other column

Hi,
I need to add a column A for my table, this column A is the same type as
another one column B. For the exsiting rows I would like this new column A to
have same value as column B, how can I do that? Thanks.ALTER TABLE YourTable
ADD COLUMN ColumnA DATATYPE_HERE NULL
UPDATE YourTable
SET ColumnA = ColumnB
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Jen" <Jen@.discussions.microsoft.com> wrote in message
news:0676BB0D-ACAF-4AF7-A698-335F84928371@.microsoft.com...
> Hi,
> I need to add a column A for my table, this column A is the same type as
> another one column B. For the exsiting rows I would like this new column A
to
> have same value as column B, how can I do that? Thanks.|||There are serveral ways you can accomplish this.
You can create your new column on the table, and then update it to be the
same as ColumnB
UPDATE tablename
set columnA = ColumnB
--
Simon Worth
"Jen" <Jen@.discussions.microsoft.com> wrote in message
news:0676BB0D-ACAF-4AF7-A698-335F84928371@.microsoft.com...
> Hi,
> I need to add a column A for my table, this column A is the same type as
> another one column B. For the exsiting rows I would like this new column A
to
> have same value as column B, how can I do that? Thanks.

add a column default value from other column

Hi,
I need to add a column A for my table, this column A is the same type as
another one column B. For the exsiting rows I would like this new column A to
have same value as column B, how can I do that? Thanks.
ALTER TABLE YourTable
ADD COLUMN ColumnA DATATYPE_HERE NULL
UPDATE YourTable
SET ColumnA = ColumnB
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Jen" <Jen@.discussions.microsoft.com> wrote in message
news:0676BB0D-ACAF-4AF7-A698-335F84928371@.microsoft.com...
> Hi,
> I need to add a column A for my table, this column A is the same type as
> another one column B. For the exsiting rows I would like this new column A
to
> have same value as column B, how can I do that? Thanks.
|||There are serveral ways you can accomplish this.
You can create your new column on the table, and then update it to be the
same as ColumnB
UPDATE tablename
set columnA = ColumnB
Simon Worth
"Jen" <Jen@.discussions.microsoft.com> wrote in message
news:0676BB0D-ACAF-4AF7-A698-335F84928371@.microsoft.com...
> Hi,
> I need to add a column A for my table, this column A is the same type as
> another one column B. For the exsiting rows I would like this new column A
to
> have same value as column B, how can I do that? Thanks.

add a column default value from other column

Hi,
I need to add a column A for my table, this column A is the same type as
another one column B. For the exsiting rows I would like this new column A t
o
have same value as column B, how can I do that? Thanks.ALTER TABLE YourTable
ADD COLUMN ColumnA DATATYPE_HERE NULL
UPDATE YourTable
SET ColumnA = ColumnB
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Jen" <Jen@.discussions.microsoft.com> wrote in message
news:0676BB0D-ACAF-4AF7-A698-335F84928371@.microsoft.com...
> Hi,
> I need to add a column A for my table, this column A is the same type as
> another one column B. For the exsiting rows I would like this new column A
to
> have same value as column B, how can I do that? Thanks.|||There are serveral ways you can accomplish this.
You can create your new column on the table, and then update it to be the
same as ColumnB
UPDATE tablename
set columnA = ColumnB
Simon Worth
"Jen" <Jen@.discussions.microsoft.com> wrote in message
news:0676BB0D-ACAF-4AF7-A698-335F84928371@.microsoft.com...
> Hi,
> I need to add a column A for my table, this column A is the same type as
> another one column B. For the exsiting rows I would like this new column A
to
> have same value as column B, how can I do that? Thanks.