Fail To Update Field With A Field Uniqueidentifier
Mar 30, 2004
Hi all,
I have a problem about a query to update a table
UPDATE Email SET EmailDT='31 Mar 2004' WHERE Idx={BDF51DBD-9E4F-4990-A751-5B25D071E288}
where Idx field is a uniqueidentifier type and EmailDT is datetime type. I found that when this query calling by a VB app. then it have error "[Microsoft][ODBC SQL Server Driver]Syntax error or access violation" and i have tried again in Query Analyzer, same error also occur, the MS SQL server is version 7. Please help. thanks.
As you know we can get the last identity by using these functions:@@IDENTITY, IDENT_CURRENT( '[Table_Name]' ) And More.But if I set my primary key datatype to uniqueidentifier, I Can't get the last GUID inserted by SQL.Anyone have any idea?Reach me at my blog: http://ramezanpour.spaces.live.com
Another table with an uniqueidentifier which references the user iD
I want to set the value of the iD in one of the entries in the second table to null.
I tried this: string assigned is null, i am passing this as a method parameter ............... string queryString = "UPDATE [table2] SET AssignedUserId=@assigned WHERE ProblemId = @id"; System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand(); ................... System.Data.IDataParameter dbParam_au_pr = new System.Data.SqlClient.SqlParameter(); dbParam_au_pr.ParameterName = "@assigned"; if (assigned == null) { dbParam_au_pr.Value = null; } else { dbParam_au_pr.Value = assigned; } dbParam_au_pr.DbType = System.Data.DbType.String ; dbCommand.Parameters.Add(dbParam_au_pr);
I also tried using "" instead of null, or not using that "if" statement at all. I get an error that says:
Parameterized Query '(@id nvarchar(1),@assigned nvarchar(4000))UPDATE [tracker_Probl' expects parameter @assigned, which was not supplied. Please help with this as soon as possible.Thanks
OK, I use asp.net membership and have created a new table that links together related users by use of the uniqueidentifier field as a foreign key. However, it is possible to link to a not-yet existent user (by their email) so that when that user creates an account and gets a guid, it will be updated into my table of related users and finalise the link. Trouble is, I'm trying to stop people adding the same "pending user" multiple times, so in my BLL logic I look for the entered email address for the current user and I want to check on the foreign key (the GUID field) so that I can tell the user that they've already added this user, but they haven't signed up yet (if they haven't got a foreign user key with a guid in it, they haven't signed up yet). However, when I check the foreign key guid value (shows as null in sql enterprise manager) for null values, it never goes down the "true" logic channel... what I mean is that I've debugged it, hovered over the item I've read (it says it is system.dbnull, which it is) and yet when I do "isDBNull(myGUID.Value)" it never equates to true! Why not?
Not a SQL guy but can do enough to be dangerous :)Trying to update a record. We have records that have a field with datasurrounded by some comment text such as *** Previous Public Solution*** Start and *** Previous Public Solution *** End . What I am tryingto do is write a SQL statement that will:Check that field C100 = TICKET0001 (to test with one record beforerunning on whole db)Check that field C101 is = ClosedCheck that field C102 is nullCopy field C103 data to field C102 and strip out any words such as ***Previous Public Solution *** Start and *** Previous Public Solution*** endThanks for any help!Kevin
I am new at ASP.net and I am having problems inserting data using C# in ASP.netI have created a table named "Profile" in the MS sql server database named "MyDataBase". There is a field named "ID" that has data type 'uniqueidentifier'.I am confused how to INSERT data into this data field. I have used MS Access and MYSQL in which there is an option of auto increment so we don't a unique identifier for each record.Please tell me what can I do to If I want to have a uniqueidentifier for each new record I INSERT in the "Profile" table of MS sql server database.While trying to insert, I get following errorsCannot insert the value NULL into column 'ID'and I don't know how I can insert something in this field that is of value type unique identifier.Please help me I will be very thankfull of you.
If I have a table with 1 or more Nullable fields and I want to make sure that when an INSERT or UPDATE occurs and one or more of these fields are left to NULL either explicitly or implicitly is there I can set these to non-null values without interfering with the INSERT or UPDATE in as far as the other fields in the table?
EXAMPLE:
CREATE TABLE dbo.MYTABLE( ID NUMERIC(18,0) IDENTITY(1,1) NOT NULL, FirstName VARCHAR(50) NULL, LastName VARCHAR(50) NULL,
[Code] ....
If an INSERT looks like any of the following what can I do to change the NULL being assigned to DateAdded to a real date, preferable the value of GetDate() at the time of the insert? I've heard of INSTEAD of Triggers but I'm not trying tto over rise the entire INSERT or update just the on (maybe 2) fields that are being left as null or explicitly set to null. The same would apply for any UPDATE where DateModified is not specified or explicitly set to NULL. I would want to change it so that DateModified is not null on any UPDATE.
INSERT INTO dbo.MYTABLE( FirstName, LastName, DateAdded) VALUES('John','Smith',NULL)
INSERT INTO dbo.MYTABLE( FirstName, LastName) VALUES('John','Smith')
INSERT INTO dbo.MYTABLE( FirstName, LastName, DateAdded) SELECT FirstName, LastName, NULL FROM MYOTHERTABLE
I'm using DTS to import data from an Access memo field into a SQL Server ntext field. DTS is only importing the first 255 characters of the memo field and truncating the rest.I'd appreciate any insights into what may be causing this problem, and what I can do about it.Thanks in advance for any help!
I need to pass in null/blank value in the date field or declare the field as string and convert date back to string.
I tried the 2nd option but I am having trouble converting the two digits of the recordset (rs_get_msp_info(2), 1, 2))) into a four digit yr. But it will only the yr in two digits. The mfg_start_date is delcared as a string variable
option 1 I will have to declare the mfg_start_date as date but I need to send in a blank value for this variable in the stored procedure. It won't accept a null or blank value.
I am trying to drag data from Informix to Sql Server. When I kick off the package using an OLE DB Source and a SQL Server Destination, I get DT_DBDATE to DT_DBTIMESTAMP errors on two fields from Informix which are date data ....no timestamp part
I tried a couple of things:
Created a view of the Informix table where I cast the date fields as datetime year to fraction(5), which failed.
Altered the view to convert the date fields to char(10) with the hopes that SQL Server would implicitly cast them as datetime but it failed.
Hi ,Have a Visual C++ app that use odbc to access sql server database.Doing a select to get value of binary field and bind a char to thatfield as follows , field in database in binary(16)char lpResourceID[32+1];rc = SQLBindCol(hstmt, 1, SQL_C_CHAR,&lpResourceID,RESOURCE_ID_LEN_PLUS_NULL , &nLen1);and this works fine , however trying to move codebase to UNICODE antested the followingWCHAR lpResourceID[32+1];rc = SQLBindCol(hstmt, 1, SQL_W_CHAR,&lpResourceID,RESOURCE_ID_LEN_PLUS_NULL , &nLen1);but only returns 1/2 the data .Any ideas , thoughts this would work fine , nit sure why loosing dataAll ideas welcome.JOhn
Hello, I have a field in a table that I have to update to the number of the week. Information i use is from another field, which is text in the format like :
01022005 02142005 07082005 11222005 ... 12022005
mmddyyyy.
How to write an update to update empty field with a number of the week based on the value from another field.
Hi,another problem I have is that have compounded fields in my sql table.Exampleproduct@customerI need a simple function to return "customer", so it should return the valueafter "@", unfortunate "@" will sometimes be character number 6, sometimescharacter number 7 etc.regardsJorgen
I have a very strange situation. I've increased the size of an NVARCHAR field from 8 to 9 in a database table. The format of the data that I enter will either be an 8 character field (123456-8) or a 9 character field (1234567-9). The '-' is critical.
It used to only accept the 8 character version, but after increasing the field size, if I try to insert the 9 character field version, it gets truncated after the '-', as though it's still only allowing 8 characters. But that only occurs when I include the '-' or other such characters like '#'. If I try to insert 1234567a9, it works. The following explains the outcomes:
if a db field "mynum" of type int contains for example the number 543.Is there a way I can update this field without first selecting the value?so for example set the the current value to +1
in sql server I want to update the "UpdatedDate" field automatically when I change ANY other field in that specific record.it has to be set to the current server time.
I am trying to update a field in a temptable with the count of items in another table. To illustrate, CustomerID=23 and I want the number of occurences in the temp table. Here's the code which DOESN'T work:
INSERT INTO TempTable ( CustomerID, FirstName, LastName, DateAdded, AlbumPicture, LayoutCount ) SELECT Albums.CustomerID, Customers.FirstName, Customers.LastName, DateAdded, AlbumPicture, COUNT(*) FROM Layouts WHERE Layout.customerID = Albums.CustomerID FROM Albums JOIN Customers on (Albums.CustomerID=Customers.CustomerID)
Please take a look at the COUNT line. Here I want to count the occurences of a specific customerid in another table and put in into th LayoutCount field.
SQL server reports "Incorrect syntax near the keyword 'FROM'". Any ideas how to achieve this?
I am updating three fields (defined as decimal(18,4) NULL) in a 1.7 million record table to 0. This table is also very wide (meaning lot of columns). A simple query like this -
Hi, I'm trying to use the Update command to change a field value. I only know the field name at run-time, how do you write this command. This is what I have done which just sets the variable @cFieldName to the value and not the field within the table.
UPDATE [Atable] SET @cFieldName = @aValue WHERE ([Id] = @Id_1)
I have a table with millions of records, table has three fields: case_id,line_no and notedata field, notedata field is 60 chars long, datatype varchar.for each case_id there could be as many as 2000 line_no meaning 2000 notes. I need to compress these notes into one note by case_no, For example case_no 1 could have 2000 lines of notes but my comressed table shoul have only one line containing all 2000 notes in line_no sequence.
my compressed table contains two fields case_no and notetext, notetext is a text field.
here is the script I am trying to use to accomplish the task but it does not append more than 8000 chars in one case, so my notes are chopping of, how should I do this, please let me know of any suggestions..
Thanks.
truncate table eldoecinotescompressed insert into eldoecinotescompressed (app_code, case_no) select distinct app_code, substring(system_key, 6,8) from eldoecinotes
DECLARE notes_cursor CURSOR FOR select substring(system_key, 6,8) case_no, line_no, rtrim(notedata) notedata FROM EldoECINotes where substring(system_key, 6,8)<>'' order by 1,2; OPEN notes_cursor; FETCH NEXT FROM notes_cursor into @case, @lineno, @note; WHILE (@@FETCH_STATUS = 0) BEGIN
BEGIN TRANSACTION; update eldoecinotescompressed set notetext = (case when isnull(datalength(notetext), 0) >= 0 then substring(isnull(notetext,''), 1, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 8000 then substring(isnull(notetext,''), 8001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 16000 then substring(isnull(notetext,''), 16001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 24000 then substring(isnull(notetext,''), 24001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 32000 then substring(isnull(notetext,''), 32001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 40000 then substring(isnull(notetext,''), 40001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 48000 then substring(isnull(notetext,''), 48001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 56000 then substring(isnull(notetext,''), 56001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 64000 then substring(isnull(notetext,''), 64001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 72000 then substring(isnull(notetext,''), 72001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 80000 then substring(isnull(notetext,''), 80001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 88000 then substring(isnull(notetext,''), 88001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 96000 then substring(isnull(notetext,''), 96001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 104000 then substring(isnull(notetext,''), 104001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 112000 then substring(isnull(notetext,''), 112001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 120000 then substring(isnull(notetext,''), 120001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 128000 then substring(isnull(notetext,''), 128001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 136000 then substring(isnull(notetext,''), 136001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 144000 then substring(isnull(notetext,''), 144001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 152000 then substring(isnull(notetext,''), 152001, 8000) else '' end ) + (case when isnull(datalength(notetext), 0) > 0 then char(13) + char(10) else '' end) + isnull(@note,'') where case_no=@case; commit; FETCH NEXT FROM notes_cursor into @case, @lineno, @note; END CLOSE notes_cursor; DEALLOCATE notes_cursor;
I am tryin t to update the tbl1_ID from the tbl2_ID. How do I do a Update Join that will do a comparison on the param column and value columns so that I could get the correct ID into tble 1. Tbl1 is my destination table and tbl2 is my source. Please Help.
ID Tbl1_ID tb1Param tbl1value
1NULLParam1 0 1NULLParam2 F 1NULLParam3 2 3NULLParam1 0 3NULLParam2 E 3NULLParam3 0 5NULLParam1 0 5NULLParam2 F 5NULLParma3 2
tbl2_ID tbl2Param tbl2value
100param1 0 101param1 1 102param1 2 103param1 3 104param1 4 105param2 E 106param2 F 107param2 H 108param2 HF 109param2 HS 110param2 L 111param2 LS 112param3 0 113param3 1 114param3 2 115param3 3 116param3 4 117param3 5 118param3 6
Here is what Im trying to do if you can understand this.
Update Tbl1 SET tb1ID = B.tbl2_ID FROM tbl1 AS A JOIN tbl2 AS B ON A.tbl1Param + A.tbl1Value = B.tbl2Param + A.tbl2value
this is the Select statment I am trying to use so that I can update the Asset in Assets table and the ESN number in the ESN table. But using ESNId and AssetId.
This is my query that returns the ones are not assigned to and Asset
SELECT DISTINCT EsnId, EsnNumber FROM dbo.ESNTracking WHERE (EsnId NOT IN (SELECT EsnId FROM dbo.EsnAsset))
Loading thousands of records to the DB through bulk insert. There's one field NText which I have left NULL because it will be hard to gen dummy flat file to it.
I have another table which has the Ntext Value which i will want to copy and duplicate to the other table.
what is the way to do it?
simply said i want to update a record with NULL value from one table with NText field with the value from another table..
I would like to append information to a varchar field with an update statement, for example the field currently contains a name (Mark) and I would like to add information to name for business purposes, to update it to Markqw215, is this possible to do with an update statement? Thank you.