MYSQL + Change path + Update substring - mysql

I have a question, i have table 'file' with a column 'path' in my DB called Pics.
Each path is like "C:\my folder\pics\pic1.jpg" etc.......
How i do to change:
C:\my folder\pics\
to
C:\my NEW folder\NEW pics\
I try a select for the path folder without the filename like this :
SELECT substring(c1,1,locate(substring_index(c1,'/',-1),c1)-1) FROM t1
that give me "C:\my folder\pics\".
Now i need to update all the column path. What is the correct query. I try this but dont work.
update foto set path = 'z' where path = (SELECT substring(path,1,locate(substring_index(path,'\\',-1),path)-1))
Thanks for sharing

Done.
update foto set path = REPLACE(path,(SELECT substring(path,1,locate(substring_index(path,'\\',-2),path)-1)),'" & TextBox2.Text & "'

Related

Parameter inside identifier

I'm trying to write a add query that will change depending on the parameter. I have several queries:
LastK1StatDate
LastK2StatDate
.
.
LastK15StatDate
LastK16StatDate
My criteria should change depending on the value entered for the parameter "qryKioskNum" when the query is run.
Currently my criteria is this:
>Max("[LastK" & [qryKioskNum] & "StatDate]![K" & [qryKioskNum] & "LastDate]")
qryKioskNum is type Short Text
It keeps giving me the error "The expression is typed incorrectly, or is too complex to be evaluated."
Here is the complete SQL statement for this query:
PARAMETERS qryKioskNum Short;
INSERT INTO K1DispRejStat ( K1StatDate, K1BillCount1, K1BillCount2,
K1BillCount3, K1BillCount4, K1BillCount5, K1BillCount6, K1BillRej1,
K1BillRej2, K1BillRej3, K1BillRej4, K1BillRej5, K1BillRej6 )
SELECT DateValue([responseFrames]![dispDateTime]) AS [Date],
Sum(responseFrames.billCount1) AS SumOfbillCount1,
Sum(responseFrames.billCount2) AS SumOfbillCount2,
Sum(responseFrames.billCount3) AS SumOfbillCount3,
Sum(responseFrames.billCount4) AS SumOfbillCount4,
Sum(responseFrames.billCount5) AS SumOfbillCount5,
Sum(responseFrames.billCount6) AS SumOfbillCount6,
Sum(responseFrames.BillRej1) AS SumOfBillRej1, Sum(responseFrames.BillRej2)
AS SumOfBillRej2, Sum(responseFrames.BillRej3) AS SumOfBillRej3,
Sum(responseFrames.BillRej4) AS SumOfBillRej4, Sum(responseFrames.billRej5)
AS SumOfbillRej5, Sum(responseFrames.billRej6) AS SumOfbillRej6
FROM responseFrames, LastK1StatDate
WHERE (((responseFrames.kioskID)="K1"))
GROUP BY DateValue([responseFrames]![dispDateTime])
HAVING (((DateValue([responseFrames]![dispDateTime]))>Max("[LastK" &
[qryKioskNum] & "StatDate]![K1LastDate]")))
ORDER BY DateValue([responseFrames]![dispDateTime]);
currently everything is set to "K1" but I would like all reference to K1 to be dynamic
I think it is just a syntax issue but can't find how exactly this should be typed out.
Any help is great. Thanks!
*edited for clarity
In msaccess, create a PassThru query (because it retains the multi-line nice format).
Create // QueryDesign // Close // rightClick // SQLSpecific // PassThru
Paste in the following sql.
INSERT INTO kxxdisprejstat
(kxxstatdate,
kxxbillcount1,
kxxbillcount2,
kxxbillcount3,
kxxbillcount4,
kxxbillcount5,
kxxbillcount6,
kxxbillrej1,
kxxbillrej2,
kxxbillrej3,
kxxbillrej4,
kxxbillrej5,
kxxbillrej6)
SELECT Datevalue([responseframes] ! [dispdatetime]) AS [Date],
SUM(responseframes.billcount1) AS SumOfbillCount1,
SUM(responseframes.billcount2) AS SumOfbillCount2,
SUM(responseframes.billcount3) AS SumOfbillCount3,
SUM(responseframes.billcount4) AS SumOfbillCount4,
SUM(responseframes.billcount5) AS SumOfbillCount5,
SUM(responseframes.billcount6) AS SumOfbillCount6,
SUM(responseframes.billrej1) AS SumOfBillRej1,
SUM(responseframes.billrej2) AS SumOfBillRej2,
SUM(responseframes.billrej3) AS SumOfBillRej3,
SUM(responseframes.billrej4) AS SumOfBillRej4,
SUM(responseframes.billrej5) AS SumOfbillRej5,
SUM(responseframes.billrej6) AS SumOfbillRej6
FROM responseframes,
lastkxxstatdate
WHERE (( ( responseframes.kioskid ) = "kxx" ))
GROUP BY Datevalue([responseframes] ! [dispdatetime])
HAVING (( ( Datevalue([responseframes] ! [dispdatetime]) )
> Max([lastkxxstatdate]![kxxlastdate]) ))
ORDER BY Datevalue([responseframes] ! [dispdatetime]);
Name it kxxInsert (or some such, using kxx to say that it is generalized).
Then add this to the program
Sub getKxx()
Dim qrykiosknum As Integer ' temp here to have something
qrykiosknum = 3 ' temp here for an example
Dim kxxSQL As String, strSQL As String
kxxSQL = CurrentDb.QueryDefs("kxxInsert").SQL
strSQL = Replace(kxxSQL, "kxx", "k" & qrykiosknum)
'MsgBox (strSQL) ' it is too big to see all of it
Debug.Print strSQL
' then run strSQL
End Sub
Having dynamic tablename in MSAccess or MSSQLServer is possible when the Replace is done before executing the SQL.
I doubt you can make this work by using a query with a parameter. You are much better off using VBA. Use InputBox to get the variable portion of the query and DoCmd.RunSQL to run the query.

Access VBA - Rename File With Periods In The Name

So, I'm attempting to rename a file (Enrollment tracking 07.30.xlsx) to "Enrollment tracking.xlsx", but it hates the period in the date, and it won't do it.
Path = "V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\"
OriginalName = Dir("V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\*Enrollment tracking*")
NewName = "V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\Enrollment tracking.xlsx"
Name Path & OriginalName As NewName
It will toss the runtime error 75: "Path/File access error"...
Is there any way to do this? I can get it to identify the file name with the "OriginalName" variable (it will show as "Enrollment tracking 07.30.xlsx"), but I can't get it to rename the file.
The periods aren't the issue, its the path.
Take a closer look at your last line:
Name Path & OriginalName As NewName
The issue is that you already put the path in the variable OriginalName, as shown below:
Path = "V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\"
OriginalName = Dir("V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\*Enrollment tracking*")
so, you're trying to rename the file under Path & Originalname, which would be:
"V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\V:\
CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\
*Enrollment tracking*"
Which would understandibly cause an error.
Try replacing your last line with simply:
Name OriginalName As NewName
I tried this approach on my computer and it worked, here's my full code:
Sub changeFileName()
origFile = "C:\Users\name\Desktop\1.2.3.txt"
NewFile = "C:\Users\name\Desktop\123.txt"
Name origFile As NewFile
End Sub
EDIT: you can actually use the Dir() function, when I tested the code above I forgot to include it. This code also worked for me, so maybe there's an error in file/path name? that's what the error seems to indicate. See code:
Sub changeFileName2()
Path = "C:\Users\name\Desktop\"
origFile = Dir("C:\Users\name\Desktop\1.2.3.txt")
NewFile = "C:\Users\name\Desktop\123.txt"
Name Path & origFile As NewFile
End Sub

Query to rename file path if it match in filepath table

In the image I have filepath and parent_path columns, The requirement is if my string is contains in filepath then replace with new string and in parent path too.
Example : E:\Images\Apple_icon.jpg search for "Images" if contains replace with "MyImages", like this=> E:\MyImages\Apple_icon.jpg
update tableName set FILEPATH=REPLACE(FILEPATH,'E:\Images\','E:\MyImages\') ,
PARENT_PATH=REPLACE(PARENT_PATH,'E:\Images','E:\MyImages')

split mysql database field into 2 parts

i am saving complete file path in single field now i want to split it. bellow is my current database file path.
Current field name is "video_thumb"
../files/thumbs/2014-Oct/1413648778-sm.jpg
now i want to split it into 2 fields
folder path in one field
i want to split the following to "thumb_path"
../files/thumbs/2014-Oct/
the file name in another field "file_name"
1413648778-sm.jpg
SET #STR = '../files/thumbs/2014-Oct/1413648778-sm.jpg';
SELECT #STR,
REVERSE(#STR) AS REVERSESTR,
REVERSE(SUBSTRING(REVERSE(#STR),1,INSTR(REVERSE(#STR),'/') - 1)) FILENAME,
REPLACE
(#STR,
REVERSE(SUBSTRING(REVERSE(#STR),1,INSTR(REVERSE(#STR),'/') -1))
,''
) AS THUMB;
I have left all the steps in to illustrate the solution
Try with a query like this :
select '/files/thumbs/2014-Oct/1413648778-sm.jpg' path_and_filename,
replace('/files/thumbs/2014-Oct/1413648778-sm.jpg', substring_index('/files/thumbs/2014-Oct/1413648778-sm.jpg', '/', -1), '') path,
substring_index('/files/thumbs/2014-Oct/1413648778-sm.jpg', '/', -1) filename
from myTable
You will have 3 fields :
path_and_filename : Original Data
path : Only path string
filename : Only filename string
XaV

Change image name and update into same table using mysql query

I want to change image name in table like below.
image name : test.png
replace with : test_E.png
I want _E at end of all image name in table using mysql query.
Use replace function
update <table>
set image=replace(image,'.png','_E.png')
you could use this, if the image extension is not same in the table
update <table>
set image=concat(substring(image,1,locate('.',image)-1),'_E',
substring(image,locate('.',image),lenght(image)))
You can use string functions of MySQL query:
UPDATE TABLE SET IMAGE_NAME = CONCAT(SUBSTR(IMAGE_NAME,(CHAR_LENGTH(IMAGE_NAME) - 4)),
'_E' , SUBSTR(IMAGE_NAME, -4)) WHERE ID = <put record id>;
SUBSTR(IMAGE_NAME,(CHAR_LENGTH(IMAGE_NAME)-4)) would return name of file - assuming extension is of 3 chars. For 'test.png' above function would remove '.png' and function would return 'test'
SUBSTR(IMAGE_NAME, -4) would return last four chars of string - so 'test.png' would return '.png'
using concat you can concat 'test', '_E' and '.png' - returning 'test_E.png'
Please refer to string functions reference of MySQL for further use
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html