Say I have a table with 2 fields
Id : int
Text : nvarchar(50)
now I want to set the text of items with ID higher than 50 to be some text but not in english
after the update query my table looks like this
Id Text
... ...
51 ????
52 ????
... ...
edit:
my query
UPDATE MyTable
SET Text = 'אבגד'
where Id > 50
put N before text like this
set Text=N'אבגד'
UPDATE MyTable
SET Text = N'אבגד'
where Id > 50
If the above code does not work then you need to check the globalisation settings of all the code that deals with this data, from your database, data access and presentation layers. This includes SSMS.
Related
I have Ticket table that has some columns like this :
ID : int
Body : nvarchar
Type : int
I have many rows where the Body column has value like this :
IPAddress = sometext, ComputerName = sometext , GetID = sometext, CustomerName=sometext-sometext , PharmacyCode = 13162900
I want update all rows' Type column where the Body column has at least five of the following keys:
IPAddress, ComputerName, GetID, CustomerName, PharmacyCode
You could do it with a simple update statement like that
UPDATE Ticket
SET Type = 4
WHERE Body LIKE '%IPAddress%'
and Body LIKE '%ComputerName%'
and Body LIKE '%GetID%'
and Body LIKE '%CustomerName%'
and Body LIKE '%PharmacyCode%'
if you know the 'keys' are always in the same order you could concatenate the LIKE conditions like so
UPDATE Ticket
SET Type = 4
WHERE Body LIKE '%IPAddress%ComputerName%GetID%CustomerName%PharmacyCode%'
If you have the possibility to change the data model it would be much better to explode this key & value column into an own table and link it back to this table as it is done in a proper relational model.
If you could calculate number of key value pair by number of = present in your string you could use this query
Update tblname set col=val where len(colname) - len(replace(colname,'=','')>5
The where part actually gives number of equal signs present in your string.
I have database table RoosterRanks. 16 ID's - 16 titles. It looks like this
... Now i need to read the id-Titles to work with them. I need titles shown in combobox. But if i go like this
sQL.Query("Select * from RoosterRanks")
cbRank.DataSource = sQL.SQLDataset.Tables(0)
cbRank.ValueMember = "Title"
cbRank.SelectedIndex = -1
But this way in combobox i also have a Blank values Because the empty fileds are not NULL they are ""
I don't need result like this
Try this query. Theres others as well, but this will give you a few options...
Select * FROM RoosterRanks
WHERE Len(Title) > 0
Or
Select * FROM RoosterRanks
WHERE Title <> ''
Or if you want to replace it with something...
Select
id,
Case Title
When NULL THEN 'Replacement'
When '' THEN 'Replacement'
End As Title
FROM RoosterRanks
On another note you probably want your Title as the DisplayMember and id as your ValueMember
I have table with name ATTACHMENT with follow columns:
COLUMN_NAME TYPE_NAME COLUMN_SIZE
---------------------------------------------------
DTYPE VARCHAR 31
ID VARCHAR 36
VERSION BIGINT 19
TYPE INTEGER 10
FILENAME VARCHAR 100
DATA BLOB 9437211
SIZE INTEGER 10
CHECKSUM BIGINT 19
AUTHOR VARCHAR 36
FILEDATE DATE 10
FILETIME TIME 8
CREATIONDATE DATE 10
CREATIONTIME TIME 8
FILETYPE INTEGER 10
SYSTEM SMALLINT 5
ORIGINALPICTUREID VARCHAR 36
COMPRESSEDPICTUREID VARCHAR 36
FIRSTUSE VARCHAR 120
And when I have run simple test SQL query:
SELECT ID FROM ATTACHMENT WHERE ORIGINALPICTUREID IS NOT NULL;
This query execute very long time (30 sec.)
But when I have run next test SQL query without IS NOT NULL expression:
SELECT ID FROM ATTACHMENT WHERE ORIGINALPICTUREID IS NULL;
This query execute only 2 sec.
In real system I have script:
select ATTACHMENT.ID,
ATTACHMENT.SIZE,
ATTACHMENT.AUTHOR,
ATTACHMENT.FILENAME,
ATTACHMENT.FILETIME,
ATTACHMENT.FILEDATE,
ATTACHMENT.CREATIONDATE,
ATTACHMENT.CREATIONTIME,
ATTACHMENT.FILETYPE,
ATTACHMENT.COMPRESSEDPICTUREID,
ATTACHMENT.ORIGINALPICTUREID,
ATTACHMENT.FIRSTUSE
from ATTACHMENT,
MESSAGECONTENT_ATTACHMENT,
MESSAGECONTENT
where ATTACHMENT.ID not in (select distinct ATTACHMENT.ORIGINALPICTUREID
from ATTACHMENT
where ATTACHMENT.ORIGINALPICTUREID is not null)
and ATTACHMENT.ID not in (select distinct COMPRESSEDPICTUREID
from ATTACHMENT
where ORIGINALPICTUREID is not null)
and MESSAGECONTENT_ATTACHMENT.MESSAGECONTENT_ID = MESSAGECONTENT.ID
and MESSAGECONTENT_ATTACHMENT.ATTACHMENTS_ID = ATTACHMENT.ID
and ATTACHMENT.DTYPE = 'P'
and MESSAGECONTENT.PERSONIDPATIENT = '0584393a-0955-4c9b-98f7-d31c991d22a3'
and (ATTACHMENT.FILENAME like '%jpeg'
or ATTACHMENT.FILENAME like '%jpg'
or ATTACHMENT.FILENAME like '%tiff'
or ATTACHMENT.FILENAME like '%tif'
or ATTACHMENT.FILENAME like '%bmp'
or ATTACHMENT.FILENAME like '%gif'
or ATTACHMENT.FILENAME like '%png'
or ATTACHMENT.FILENAME like '%ser')
and this script execute very, very long time.
Could you please help me how I can solve problem with IS NOT NULL expression in my SQL query in my Derby DB?
Thank you very much!
You are killing yourself on this query primarily due to your distinct of not nulls... You are blowing through ALL ATTACHMENTS TWICE for original and compressed respectively, yet you are only interested in a single patient. I've restructured the query to START with the WHO you want... The patientPersonID. From that, join to the message attachments. You only care about anything that is attached to this ONE PERSON. This should result in a very small set of records. Of THOSE records, only THOSE do you care to look at the attachment table itself and see if any qualify for your DPTYPE, like condition and IS NULL.
I would ensure you have an index on your messagecontent table on (PersonIDPatient) at a minimum, and if any other columns AFTER the first position, no problem. The joins to the other tables appear to be on their respective primary ID column and would assume that you have indexes on those.
SELECT
atch.ID,
atch.SIZE,
atch.AUTHOR,
atch.FILENAME,
atch.FILETIME,
atch.FILEDATE,
atch.CREATIONDATE,
atch.CREATIONTIME,
atch.FILETYPE,
atch.COMPRESSEDPICTUREID,
atch.ORIGINALPICTUREID,
atch.FIRSTUSE
FROM
MESSAGECONTENT msgCont
JOIN MESSAGECONTENT_ATTACHMENT msgAtt
ON msgCont.ID = msgAtt.MESSAGECONTENT_ID
JOIN ATTACHMENT atch
ON msgAtt.ATTACHMENTS_ID = atch.ID
AND atch.DTYPE = 'P'
AND atch.ORIGINALPICTUREID IS NOT NULL
AND atch.CompressedPictureID IS NOT NULL
AND ( atch.FILENAME LIKE '%jpeg'
OR atch.FILENAME LIKE '%jpg'
OR atch.FILENAME LIKE '%tiff'
OR atch.FILENAME LIKE '%tif'
OR atch.FILENAME LIKE '%bmp'
OR atch.FILENAME LIKE '%gif'
OR atch.FILENAME LIKE '%png'
OR atch.FILENAME LIKE '%ser')
WHERE
msgCont.PersonIDPatient = '0584393a-0955-4c9b-98f7-d31c991d22a3'
NOT IN operator in queries does not make use of any indexes. -
Avoid using NOT IN operator in your queries.
In order to to find results which does NOT meet a certain criteria it has to check ALL the records against the condition, which makes presences of indexes irrelevant.
Also instead of using wildcard % try making use of Full-Text indexes and query the database something like
Select Col1, Col2 , .......
from Table
Where Col1 CONTAINS(Col1,'Search') AND Col1 CONTAINS(Col1,'Search2').........
I'm a novice in mySql.
I'm trying to replace a value in the xml column of my table.
my select method works.
SELECT * FROM `comics` WHERE ExtractValue(xml,'comic/pageNumber') = 6
my replace method doesn't. I've been searching for the correct syntax for a bit now...
SET xml.modify(
replace value of ('comic/pageNumber') with 5
)
some background:
this situation comes up when i delete a comic page.
it leaves a gap in the page numbers, after which i would either:
iterate through all the comics and remove any gaps in the page numbers.
or
iterate through all comics with pageNumber larger than the deleted page, and reduce their pageNumber by 1.
How about
UPDATE comics
SET xml = UpdateXML(xml,'comic/pageNumber', '<pageNumber>5</pageNumber>')
WHERE ExtractValue(xml,'comic/pageNumber') = 6
Tested on MySQL version 5.1
UPDATE `comics`
SET xml = UpdateXML(xml,
'comic/pageNumber',
concat('<pageNumber>',(ExtractValue(xml,'comic/pageNumber')+1),'</pageNumber>'))
WHERE ExtractValue(xml,'comic/pageNumber') >= 1
You'd be better off actually storing the fields in the table, rather than a single field with xml in it. Then the following would work. Otherwise there's not much point using a relational database at all.
BEGIN;
DELETE FROM `comics`
WHERE `comicID` = :id AND `pageNumber` = :page;
UPDATE `comics` SET `pageNumber` = `pageNumber` - 1
WHERE `comicID` = :id AND `pageNumber` > :page;
COMMIT;
I imported an e-store's database values into my own, and it mostly worked out fine. However, there were no image file names. So, I need to update the entire database- over 6,000 records, so that under 'image' we get a path + model name + jpg, so each product can be associated with an image. Im having trouble mixing the dynamic column value with the static path. Here is what I need to accomplish:
UPDATE `store`.`pr_product`
SET `image` = 'data/products/`**model_no**`.jpg'
WHERE `pr_product`.`product_id` = `pr_product`.`product_id` ;
But cannot get it to recognize the dynamic nature of 'model_no'
Thanks in advance
Max,
Please what you means about dynamic nature of 'model_no'?
Is this column's datatype int or long or varchar
Please need more explaination with example
you can test the following if e.g model_no is column in pr_product table
UPDATE store.pr_product
SET image = 'data/products/'+pr_product.model_no+'.jpg'
WHERE pr_product.product_id = pr_product.product_id ;
Best Regards,
Mohammed Thabet Zaky