Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query request pls

Author  Topic 

Dickie.wild
Starting Member

6 Posts

Posted - 2010-10-16 : 14:58:53
Hi All,

I was hopeing for a little help, well little would be an understatement, I currently have a file location in a field and i would like to take all of it up untill the last / (folder) and copy it in to another column and then attach folder.jpg on the end. So the end result ends up being something like c:\rich\Eminem\folder.jpg

I am pretty sure this is possible but my lack of knowledge is holding me back a little.

Any help greatly appriecated,

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-16 : 15:12:52
Please show us a data example of what's in the column to be more clear.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Dickie.wild
Starting Member

6 Posts

Posted - 2010-10-16 : 15:22:42
Hi, thanks for your very prompt reply, The data i would like to move is generally like: D:\Downloads\Vid's\Movies\21 Grams\21 Grams.avi although the path from Vid's changes a little this is contained with a column called strPath and the Table is called video_files.

i would then like to move the information minus the file name into a table called strCover with folder.jpg added for each record. if i have totally miss understood the request please let me know,

Thanks,
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-16 : 17:35:04
Do your folders actually contain the single quotes? It matters because we'll need to escape them.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-16 : 17:39:50
ok...I got the why...but HOW are you trying to do this?

with xp_cmdshell?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-16 : 17:44:18
Here's an example via T-SQL if you just want to change data:

DECLARE @s varchar(200)

SET @s = 'D:\Downloads\Vid''s\Movies\21 Grams\21 Grams.avi'

SELECT LEFT(@s, DATALENGTH(@s) - CHARINDEX('\', REVERSE(@s)) + 1) + 'folder.jpg'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Dickie.wild
Starting Member

6 Posts

Posted - 2010-10-16 : 17:52:16
Hi Both,

The folder location, does include single quote's, which i know can be a pain with SQL, i am currently tying to do this via SQL Lite Browser but this seems to crash when ever i try and run a query, so i might try and install MS SQL to get this done. Tk, will this not set all of the records to the same location?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-16 : 17:55:20
It's dynamic. It doesn't matter what the path is.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Dickie.wild
Starting Member

6 Posts

Posted - 2010-10-16 : 17:58:58
i kinda of see how that works now, do yo mind if for my curosity how it knows which column to put that it?

Thanks for your help,
Rich
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-16 : 18:03:26
Swap @s for your column and put a FROM for your table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Dickie.wild
Starting Member

6 Posts

Posted - 2010-10-16 : 20:05:08
Hi All,

I have just found out the DB is SQLite and the above T-SQL does not seem to do anything. I appologise for the hassle and the work you have put in Tara. I am assuming there is a different way to do it in SQLite.

Thanks and sorry again,
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-16 : 23:34:23
No problem, it only took a couple of minutes to work up. I have no knowledge of SQLite, so I'm unable to help you with that.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Dickie.wild
Starting Member

6 Posts

Posted - 2010-10-17 : 04:40:40
No worries, is it possible to do this in SQL and not. T-SQL, I am wondering weatherthat would work? Clutching at straws now
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-17 : 13:51:49
T-SQL is SQL. It's just the Microsoft flavor of SQL. I'd suggest searching for forums that deal with SQLite. There are many dbms forums over at dbforums.com, you could try there.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -