Showing posts with label varchar. Show all posts
Showing posts with label varchar. Show all posts

Friday, March 23, 2012

Problem with a Validation

Hi...

I was with a problem....

I have a table with this model:

Create Table Test
(
Id_Charge Int Not Null,
Description Varchar Not Null
)

For the rule, this column Id_Charge must be incremental and when the number arrive to 999 he must be reseted to 1, with this storage for exemple:

1 AAA
2 BBB
(...)
998 YYY
999 ZZZ
1 AAB
2 BBC
(...)

I would like to keep this control for the database system, but I don't know when I make this, somebody has a idea?

Tks...

Bruno,

Here's what I've come up with. It's not very pretty but works (for single inserts). If you want to handle mutlirow inserts you shoudl get a cursor on inserted and then handle them one by one the same way as done here.

You really should some unique colomn on the table though....

Hope this helps,

Regards John

Code Snippet

create Table Test

(

Id_Charge Int Not Null,

Description Varchar(50) Not Null

)

-- tavle to keep track of last issued ID

create table LastId

(

Id int not null

)

-- set first value

insert LastID (Id) values( 1)

go

-- trigger to handle inserts

create trigger Test_NextID on Test instead of insert

as

declare @.NextId int,

@.Desc varchar(50),

@.InsertedCount int

-- make sure we're dealng with just 1 row being inserted (otherwise get a cursor on Inserted and handle them one by one)

select @.InsertedCount = Count(*) from inserted

if @.InsertedCount > 1

begin

rollback tran

raiserror ('Can only handle single inserts', 16, 1)

return

end

-- update table to next Id

update LAstID

set Id = case Id when 999 then 1 else Id + 1 end

-- get last id

select @.NextId = Id

from LastID

-- find the value that was inserted

select @.Desc = Description from inserted

insert Test (Id_Charge, Description)

values (@.NextID, @.Desc)

go

-- insert some testdata

insert TEst (Description) values ('AAA')

insert TEst (Description) values ('BBB')

insert TEst (Description) values ('CCC')

insert TEst (Description) values ('DDD')

-- skip ahead some

update lastID set Id = 997

insert TEst (Description) values ('AAA')

insert TEst (Description) values ('BBB')

insert TEst (Description) values ('CCC')

insert TEst (Description) values ('DDD')

select * from test

-- throws error

insert TEst (Description)

select description from TEst

|||

John, thank you very much... your solution is perfect for my problem...

Bruno.

problem with a stored procedure

Hello guys,
I have again problem with a stored procedure in sql server.
I would like to execute this query
declare @.sSQL varchar(255)
SET @.sSQL =
'SELECT TOP 1 [value], date, name, [times]
FROM (SELECT value, date, times, name
FROM view
WHERE ValueDate =
(SELECT MAX(date)
AS maxdate
FROM view
v
WHERE (date
BETWEEN ''2006-02-01'' AND ''2006-02-28''))) Newtable
WHERE (name = ''TEST'')
GROUP BY [value], date, [times], name
ORDER BY [times] DESC'
EXEC (@.sSQL)
When I execute the query I have no problem but ... when i tried to
stored it I have this several problem I do not know why ... something
like
Line 4: Incorrect syntax near '='
I would like be able to pass variable on it and create function to
store the results in a table.
Please someone could help me on that.
Inaina
Replace EXEC(@.sql) with PRINT @.sql in order to debug and try run it in the
QA.
"ina" <roberta.inalbon@.gmail.com> wrote in message
news:1144763910.125857.198630@.e56g2000cwe.googlegroups.com...
> Hello guys,
> I have again problem with a stored procedure in sql server.
> I would like to execute this query
> declare @.sSQL varchar(255)
>
> SET @.sSQL =
> 'SELECT TOP 1 [value], date, name, [times]
> FROM (SELECT value, date, times, name
> FROM view
> WHERE ValueDate =
> (SELECT MAX(date)
> AS maxdate
> FROM view
> v
> WHERE (date
> BETWEEN ''2006-02-01'' AND ''2006-02-28''))) Newtable
> WHERE (name = ''TEST'')
> GROUP BY [value], date, [times], name
> ORDER BY [times] DESC'
> EXEC (@.sSQL)
> When I execute the query I have no problem but ... when i tried to
> stored it I have this several problem I do not know why ... something
> like
> Line 4: Incorrect syntax near '='
> I would like be able to pass variable on it and create function to
> store the results in a table.
> Please someone could help me on that.
> Ina
>|||> When I execute the query I have no problem but ... when i tried to
> stored it
What does "tried to stored it" mean?

> I would like be able to pass variable on it and create function to
> store the results in a table.
Well, you can't execute dynamic SQL inside a function. If you provide
better specifications on exactly what you are trying to accomplish (instead
of describing how you are already trying to accomplish it), we may be able
to provide better assistance.|||Is it actually spanning multiple lines in your stored procedure? I don't
think this is allowed. Strings have to be contained on a single line.
Either put everything on one line, or concatenate each line to the end of
@.sSQL
Also, 255 is probably not long enough to contain your SQL. Bump this up to
2000 and it should handle most reasonable sql statements.
Lastly, don't ever use dynamic SQL if you have a choice. There are times
when it is needed, but you should simply be able to pass the parameters
inside the stored procedure without dynamic SQL.
Look up "Parameters" in books on line for an explanation of how to use them.
"ina" <roberta.inalbon@.gmail.com> wrote in message
news:1144763910.125857.198630@.e56g2000cwe.googlegroups.com...
> Hello guys,
> I have again problem with a stored procedure in sql server.
> I would like to execute this query
> declare @.sSQL varchar(255)
>
> SET @.sSQL =
> 'SELECT TOP 1 [value], date, name, [times]
> FROM (SELECT value, date, times, name
> FROM view
> WHERE ValueDate =
> (SELECT MAX(date)
> AS maxdate
> FROM view
> v
> WHERE (date
> BETWEEN ''2006-02-01'' AND ''2006-02-28''))) Newtable
> WHERE (name = ''TEST'')
> GROUP BY [value], date, [times], name
> ORDER BY [times] DESC'
> EXEC (@.sSQL)
> When I execute the query I have no problem but ... when i tried to
> stored it I have this several problem I do not know why ... something
> like
> Line 4: Incorrect syntax near '='
> I would like be able to pass variable on it and create function to
> store the results in a table.
> Please someone could help me on that.
> Ina
>|||> Is it actually spanning multiple lines in your stored procedure? I don't
> think this is allowed. Strings have to be contained on a single line.
Strings can span lines. The only (obvious) limitation is the fact that they
need to be enclosed in single quotes.
ML
http://milambda.blogspot.com/|||Thank you for your help and I am sorry ... but I am really newbie and I
am trying to introduce my self in sql server programming.
What I am trying to do it is:
My main query gives to me the max value for a ticket during a period of
time. What I would like to do is the to have the max value for each end
of month for a ticket. each ticket has its own creation date and as
this period I would like to have the max value until today.
For example:
NameTicket |creation_date |month |year |value
----
-
Ticket1 2005-09-15 September 2005 120
ticket 1 2005-09-15 October 2005 125
Ticket 1 2005-09-15 November 2005 152
Ticket 1 2005-09-15 December 2005 152
Sometimes there is no value for one month so it needs to take the max
value for the previous month.
What I would like to do with my query is how to set parameter for sql,
in that what I can set the ticketname and period.
Thank you a lot for your help
Ina|||Thank you for your help and I am sorry ... but I am really newbie and I
am trying to introduce my self in sql server programming.
What I am trying to do it is:
My main query gives to me the max value for a ticket during a period of
time. What I would like to do is the to have the max value for each end
of month for a ticket. each ticket has its own creation date and as
this period I would like to have the max value until today.
For example:
NameTicket |creation_date |month |year |value
----
-
Ticket1 2005-09-15 September 2005 120
ticket 1 2005-09-15 October 2005 125
Ticket 1 2005-09-15 November 2005 152
Ticket 1 2005-09-15 December 2005 152
Sometimes there is no value for one month so it needs to take the max
value for the previous month.
What I would like to do with my query is how to set parameter for sql,
in that what I can set the ticketname and period.
Thank you a lot for your help
Ina|||This sounds better and fairly simple to acomplish. All we need now is DDL an
d
sample data.
This article will help you help us:
http://www.aspfaq.com/etiquette.asp?id=5006
ML
http://milambda.blogspot.com/|||Thank you I will go through that and try to find the solution of my
problem. Thank you :D|||Hello,
I tried to see that but what I need it is to have the max of each month
since the startdate until endate. I already have the max of the period
a set. how to have the list of all period.
Can I use the function month() to accomplish it?
ina

problem with a stored procedure

Hello guys,
I have again problem with a stored procedure in sql server.
I would like to execute this query
declare @.sSQL varchar(255)
SET @.sSQL =
'SELECT TOP 1 [value], date, name, [times]
FROM (SELECT value, date, times, name
FROM view
WHERE ValueDate =
(SELECT MAX(date)
AS maxdate
FROM view
v
WHERE (date
BETWEEN ''2006-02-01'' AND ''2006-02-28''))) Newtable
WHERE (name = ''MIREMONT TEST'')
GROUP BY [value], date, [times], name
ORDER BY [times] DESC'
EXEC (@.sSQL)
When I execute the query I have no problem but ... when i tried to
stored it I have this several problem I do not know why ... something
like
Line 4: Incorrect syntax near '='
I would like be able to pass variable on it and create function to
store the results in a table.
Please someone could help me on that.
InaI think variable @.sSQL je very short:
Try declare @.sSQL varchar(2000)
"ina" wrote:

> Hello guys,
> I have again problem with a stored procedure in sql server.
> I would like to execute this query
> declare @.sSQL varchar(255)
>
> SET @.sSQL =
> 'SELECT TOP 1 [value], date, name, [times]
> FROM (SELECT value, date, times, name
> FROM view
> WHERE ValueDate =
> (SELECT MAX(date)
> AS maxdate
> FROM view
> v
> WHERE (date
> BETWEEN ''2006-02-01'' AND ''2006-02-28''))) Newtable
> WHERE (name = ''MIREMONT TEST'')
> GROUP BY [value], date, [times], name
> ORDER BY [times] DESC'
> EXEC (@.sSQL)
> When I execute the query I have no problem but ... when i tried to
> stored it I have this several problem I do not know why ... something
> like
> Line 4: Incorrect syntax near '='
> I would like be able to pass variable on it and create function to
> store the results in a table.
> Please someone could help me on that.
> Ina
>

Problem with a SP. Help!

Why does only the first INSERT statement work?

CREATE PROCEDURE insert_inventory
@.item_name varchar(20),
@.description varchar(100),
@.notes varchar(255),
@.amount varchar(8)
AS
DECLARE @.item_id int
DECLARE @.transaction_date datetime

IF (@.item_name = '') SET @.item_name = NULL
IF (@.description = '') SET @.description = NULL
IF (@.notes = '') SET @.notes = NULL
IF (@.amount = '') SET @.amount = NULL

SET @.item_id = IDENT_CURRENT('inventory')
SET @.transaction_date = GETDATE()

INSERT INTO inventory (item_name, item_description, notes) VALUES (@.item_name, @.description, @.notes)

INSERT INTO expenditure (item_id, transaction_date, amount) VALUES (@.item_id, @.transaction_date, CAST(@.amount AS money))

Also, where I have IF(@.blah = '') SET...

I use these to convert blank fields in VB6 to NULL values, is there any easier way?do you get any error on the second insert?

if @.blah='' set... can be removed, but you will have to check for the value somewhere if you care for it: either in your vb6, in the if as you do now, or in the values clause (...values (nullif(@.blah, ''), ...)|||Try to change your SP this way (you have to get id after insert - not before):

SET @.transaction_date = GETDATE()
begin tran
INSERT INTO inventory (item_name, item_description, notes) VALUES (@.item_name, @.description, @.notes)
if @.@.error<>0 begin
rollback
return
end
SET @.item_id = IDENT_CURRENT('inventory')

INSERT INTO expenditure (item_id, transaction_date, amount) VALUES (@.item_id, @.transaction_date, CAST(@.amount AS money))
commit|||i think ident_current(..) returns the _last_ new identity value for the specified table, not the identity value generated by the current scope. in this case if your insert occurred before another insert in another scope you may acquire the value that is not yours. scope_identity() guarantees that identity value belongs to insert from your session.

also, it's better to write the error handler this way:

declare @.error int, @.id int
...insert operation
select @.error = @.@.error, @.id = scope_identity()
if @.error <> 0 begin
raiserror (...)
rollback tran
return (1)
end
commit tran|||Cheers, for those, they were all good recommendations which I am now using, but it still would only execute the first INSERT statement. That is until I used this:

SET NOCOUNT ON

Works beautifully now!!!

Rayden

Wednesday, March 21, 2012

problem with >>insert into varchar field shows "?"

i would like to insert thai characters into varchar field in Database. and show that to a label.

now the problem is when i insert into database it becomes "?"

and when i display to Lable also "?".

is there anyway to fix this?

input comes from Textbox(vb.net)

output to Label.

thanks.

thompson.

You need to specifically 'tell' SQL Server that the incoming data is UNICODE. The common method to do that is to preface the data with the letter [ N ].

It would be done something like this:

INSERT INTO MyTable ( MyColumn ) VALUES ( N'MyUnicodeValue' )

|||

Including Arnie Rowland's suggestion, check the datatype of your table column. It shoule be NVarchar. Varchar only supports ASCII chars, if you want to insert Unicode values then it should be NVarchar/NChar/NText datatype.

Note: Varchar is not equal to NVarchar

|||thanks to everyone answer this post. the problem has been solved.

problem with >>insert into varchar field shows "?"

i would like to insert thai characters into varchar field in Database. and show that to a label.

now the problem is when i insert into database it becomes "?"

and when i display to Lable also "?".

is there anyway to fix this?

input comes from Textbox(vb.net)

output to Label.

thanks.

thompson.

You need to specifically 'tell' SQL Server that the incoming data is UNICODE. The common method to do that is to preface the data with the letter [ N ].

It would be done something like this:

INSERT INTO MyTable ( MyColumn ) VALUES ( N'MyUnicodeValue' )

|||

Including Arnie Rowland's suggestion, check the datatype of your table column. It shoule be NVarchar. Varchar only supports ASCII chars, if you want to insert Unicode values then it should be NVarchar/NChar/NText datatype.

Note: Varchar is not equal to NVarchar

|||thanks to everyone answer this post. the problem has been solved.

Tuesday, March 20, 2012

Problem whith insert into SQL server from webservice

My webservice is suppoed to insert a row into my SQL server database. Al columns are varchar(String). When we insert with digits everything is ok, but when we try letters as parameters i get this error message:

"An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in system.web.services.dll

Additional information: Server was unable to process request. --> The name 'Bob' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted."

Any idea?Show the code that is creating the INSERT statement. Presuming Bob is a string you are trying to insert, are you either using parameters (best solution) or alternately, enclosing the variable in quotes in the resulting string.|||I solved the problems by using parameters instead. Thank you! :)|||Glad to hear it. Parameters eliminate all sorts of problems, in addition to making your application much more secure.

Monday, February 20, 2012

problem using default value in SP

I created an SP for searching rows in a table.
Create Proc stp_search
@.recID varchar(100) = '%'
As
Select * from tbl1
Where recID In (coalesce((select * from dbo.udf(@.recID)), recID))
The SP works if I pass in only 1 recordID, or if I don't pass in anything
(default val of %). But I want to be able to search for multiple recID's, s
o
I created a UDF that returns a table of recID's. If the UDF returns one
recID in the return table, the SP works fine. But if I pass in a string wit
h
2 or more recID's (separated by commas - thus varchar), I get this error
message:
'Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as an
expression.
The statement has been terminated.'
My goal is to be able to pass in multiple recID's, or just one, or none -
using the default value. My options to achieve this is to have multiple
select statements like this wrapped inside of IF Else:
if (select len(@.recID) - len(replace(@.recID, ',', '') = 0
select * from tbl1 where recID in coalesce(@.recID, recID)
Else
select * from tbl1 where recID in (select * from dbo.udf(@.recID)
The problem is that the actual select statment is quite large and I have 10
parameters. So the IF else thing would be quite verbose (because I am
actually searching on several tables in this SP - one of the params specifie
s
which table).
So my question is if there is a way to implement the functionality of my
UDF which can return more than one value in the subquery (searching on more
than one recID) and still be able to use the default value (with coalesce)
without having to do the If Else thing.
Any suggestions appreciated (I hope I am not stuck with verbose - it would
be a book)
Thanks,
RichSee if this helps.
Arrays and Lists in SQL Server
http://www.sommarskog.se/arrays-in-sql.html
AMB
"Rich" wrote:

> I created an SP for searching rows in a table.
> Create Proc stp_search
> @.recID varchar(100) = '%'
> As
> Select * from tbl1
> Where recID In (coalesce((select * from dbo.udf(@.recID)), recID))
> The SP works if I pass in only 1 recordID, or if I don't pass in anything
> (default val of %). But I want to be able to search for multiple recID's,
so
> I created a UDF that returns a table of recID's. If the UDF returns one
> recID in the return table, the SP works fine. But if I pass in a string w
ith
> 2 or more recID's (separated by commas - thus varchar), I get this error
> message:
> 'Subquery returned more than 1 value. This is not permitted when the
> subquery follows =, !=, <, <= , >, >= or when the subquery is used as an
> expression.
> The statement has been terminated.'
> My goal is to be able to pass in multiple recID's, or just one, or none -
> using the default value. My options to achieve this is to have multiple
> select statements like this wrapped inside of IF Else:
> if (select len(@.recID) - len(replace(@.recID, ',', '') = 0
> select * from tbl1 where recID in coalesce(@.recID, recID)
> Else
> select * from tbl1 where recID in (select * from dbo.udf(@.recID)
> The problem is that the actual select statment is quite large and I have 1
0
> parameters. So the IF else thing would be quite verbose (because I am
> actually searching on several tables in this SP - one of the params specif
ies
> which table).
> So my question is if there is a way to implement the functionality of my
> UDF which can return more than one value in the subquery (searching on mor
e
> than one recID) and still be able to use the default value (with coalesce)
> without having to do the If Else thing.
> Any suggestions appreciated (I hope I am not stuck with verbose - it would
> be a book)
> Thanks,
> Rich
>|||I think that my real question should be
Is there a way to implement a form of If Else inside a Where clause?
Declare @.recIDLen int
select @.recIDLen = len(@.recID) - len(replace(recID, ',',''))
select * from tbl1 Where
Case when @.recIDLen = 0 Then recID = coalesce(@.recID, recID)
Case When @.recIDLen > 0 Then recID In (select * from dbo.UDF(@.recID))
Is there a way to do something like this?
"Rich" wrote:

> I created an SP for searching rows in a table.
> Create Proc stp_search
> @.recID varchar(100) = '%'
> As
> Select * from tbl1
> Where recID In (coalesce((select * from dbo.udf(@.recID)), recID))
> The SP works if I pass in only 1 recordID, or if I don't pass in anything
> (default val of %). But I want to be able to search for multiple recID's,
so
> I created a UDF that returns a table of recID's. If the UDF returns one
> recID in the return table, the SP works fine. But if I pass in a string w
ith
> 2 or more recID's (separated by commas - thus varchar), I get this error
> message:
> 'Subquery returned more than 1 value. This is not permitted when the
> subquery follows =, !=, <, <= , >, >= or when the subquery is used as an
> expression.
> The statement has been terminated.'
> My goal is to be able to pass in multiple recID's, or just one, or none -
> using the default value. My options to achieve this is to have multiple
> select statements like this wrapped inside of IF Else:
> if (select len(@.recID) - len(replace(@.recID, ',', '') = 0
> select * from tbl1 where recID in coalesce(@.recID, recID)
> Else
> select * from tbl1 where recID in (select * from dbo.udf(@.recID)
> The problem is that the actual select statment is quite large and I have 1
0
> parameters. So the IF else thing would be quite verbose (because I am
> actually searching on several tables in this SP - one of the params specif
ies
> which table).
> So my question is if there is a way to implement the functionality of my
> UDF which can return more than one value in the subquery (searching on mor
e
> than one recID) and still be able to use the default value (with coalesce)
> without having to do the If Else thing.
> Any suggestions appreciated (I hope I am not stuck with verbose - it would
> be a book)
> Thanks,
> Rich
>|||try this
select * from tbl1 Where
(@.recIDLen = 0 and recID = coalesce(@.recID, recID)) or
(recID In (select * from dbo.UDF(@.recID))
"Rich" wrote:
> I think that my real question should be
> Is there a way to implement a form of If Else inside a Where clause?
> Declare @.recIDLen int
> select @.recIDLen = len(@.recID) - len(replace(recID, ',',''))
> select * from tbl1 Where
> Case when @.recIDLen = 0 Then recID = coalesce(@.recID, recID)
> Case When @.recIDLen > 0 Then recID In (select * from dbo.UDF(@.recID))
> Is there a way to do something like this?
>
> "Rich" wrote:
>|||Thanks all for your replies. And Omnibuzz gave me an even better idea. I
will add a varchar parameter which gets the string of recordIDs or default
value of '%'. If this param is '%' then @.recordID int will be used as the
parameter of choice. I was having a problem with the recID column which is
actually an int.
Anyway, this also solved another problem I was having pulling date columns
that contain nulls. I can bypass using a date params with the OR operator.
Thanks again.
"Rich" wrote:

> I created an SP for searching rows in a table.
> Create Proc stp_search
> @.recID varchar(100) = '%'
> As
> Select * from tbl1
> Where recID In (coalesce((select * from dbo.udf(@.recID)), recID))
> The SP works if I pass in only 1 recordID, or if I don't pass in anything
> (default val of %). But I want to be able to search for multiple recID's,
so
> I created a UDF that returns a table of recID's. If the UDF returns one
> recID in the return table, the SP works fine. But if I pass in a string w
ith
> 2 or more recID's (separated by commas - thus varchar), I get this error
> message:
> 'Subquery returned more than 1 value. This is not permitted when the
> subquery follows =, !=, <, <= , >, >= or when the subquery is used as an
> expression.
> The statement has been terminated.'
> My goal is to be able to pass in multiple recID's, or just one, or none -
> using the default value. My options to achieve this is to have multiple
> select statements like this wrapped inside of IF Else:
> if (select len(@.recID) - len(replace(@.recID, ',', '') = 0
> select * from tbl1 where recID in coalesce(@.recID, recID)
> Else
> select * from tbl1 where recID in (select * from dbo.udf(@.recID)
> The problem is that the actual select statment is quite large and I have 1
0
> parameters. So the IF else thing would be quite verbose (because I am
> actually searching on several tables in this SP - one of the params specif
ies
> which table).
> So my question is if there is a way to implement the functionality of my
> UDF which can return more than one value in the subquery (searching on mor
e
> than one recID) and still be able to use the default value (with coalesce)
> without having to do the If Else thing.
> Any suggestions appreciated (I hope I am not stuck with verbose - it would
> be a book)
> Thanks,
> Rich
>

problem updating text datatype

Hi All:
I am having trouble updating a TEXT column (I know that TEXT is a blob but I
am dealing with very large amounts of data that VARCHAR can not hold!) What
I want to happen is all rows from TableA that meet a certain criteria to be
inserted into TableB but if it already exists in TableB then update it
instead - this sounds simple enough and is working fine except that one of
the fields is TEXT datatype. So when I try to update I get an error "The
text, ntext, and image datatypes are invalid in this subquery or aggregate
expression." (Apparently you can not do an update select with a text
datatype) I did a search and found that I need to be using the UPDATETEXT
function - however I am not quite sure how this works. Any suggestions
would be greatly appreciated!
TableA
ID INT
MenuID INT
Content TEXT
TableB
ID INT
MenuID INT
Content TEXT
Thanks!Nancy,
Without seeing the query, it's impossible to know what the
problem is. Post the query that is causing the error, at
least, if you want a more specific answer.
In any case, it is certainly possible to update [text]
with an UPDATE statement. In general, you may want
something like this:
update TableB set
Content = TableA.Content
from TableA join TableB
on TableA.ID = TableB.ID
and TableA.MenuID = TableB.MenuID
insert into TableB(ID, MenuID, Content)
select ID, MenuID, Content
from TableA
where not exists (
select * from TableB as B2
where B2.ID = TableA.ID
and B2.MenuID = TableA.MenuID
)
Steve Kass
Drew University
Nancy Shelley wrote:

> Hi All:
> I am having trouble updating a TEXT column (I know that TEXT is a blob but
I
> am dealing with very large amounts of data that VARCHAR can not hold!) Wha
t
> I want to happen is all rows from TableA that meet a certain criteria to
be
> inserted into TableB but if it already exists in TableB then update it
> instead - this sounds simple enough and is working fine except that one of
> the fields is TEXT datatype. So when I try to update I get an error "The
> text, ntext, and image datatypes are invalid in this subquery or aggregate
> expression." (Apparently you can not do an update select with a text
> datatype) I did a search and found that I need to be using the UPDATETEXT
> function - however I am not quite sure how this works. Any suggestions
> would be greatly appreciated!
>
> TableA
> ID INT
> MenuID INT
> Content TEXT
> TableB
> ID INT
> MenuID INT
> Content TEXT
> Thanks!
>|||Hi Steve:
Thanks for the quick response. Supplying BLOB columns with text or image
data that's less than or equal to 8000 bytes in size is as straightforward
as updating any other type of column (you can use insert/update) but when
values are larger than 8000 you need to use updatetext or writetext. This
is what I was having trouble with - I know the syntax for updating my table
the regular way I just wasn't sure about using updatetext or writetext.
I ended up solving my own problem - my pointer was invalid. I was getting
an invalid pointer reference to the text column.
Thanks for your help!
Nancy
"Steve Kass" <skass@.drew.edu> wrote in message
news:OqsmT2jWFHA.3488@.tk2msftngp13.phx.gbl...
> Nancy,
> Without seeing the query, it's impossible to know what the
> problem is. Post the query that is causing the error, at
> least, if you want a more specific answer.
> In any case, it is certainly possible to update [text]
> with an UPDATE statement. In general, you may want
> something like this:
>
> update TableB set
> Content = TableA.Content
> from TableA join TableB
> on TableA.ID = TableB.ID
> and TableA.MenuID = TableB.MenuID
> insert into TableB(ID, MenuID, Content)
> select ID, MenuID, Content
> from TableA
> where not exists (
> select * from TableB as B2
> where B2.ID = TableA.ID
> and B2.MenuID = TableA.MenuID
> )
> Steve Kass
> Drew University
> Nancy Shelley wrote:
>|||Nancy,
I believe the syntax I suggested works for any length [text] or
[image] column.
You can also update or insert data into a text or image column if you
provide
it as a literal string or binary value. The 8000 byte limit does not
apply to
literals.
SK
Nancy Shelley wrote:

>Hi Steve:
>Thanks for the quick response. Supplying BLOB columns with text or image
>data that's less than or equal to 8000 bytes in size is as straightforward
>as updating any other type of column (you can use insert/update) but when
>values are larger than 8000 you need to use updatetext or writetext. This
>is what I was having trouble with - I know the syntax for updating my tabl
e
>the regular way I just wasn't sure about using updatetext or writetext.
>I ended up solving my own problem - my pointer was invalid. I was getting
>an invalid pointer reference to the text column.
>Thanks for your help!
>Nancy
>"Steve Kass" <skass@.drew.edu> wrote in message
>news:OqsmT2jWFHA.3488@.tk2msftngp13.phx.gbl...
>
>
>