Yesterday evening one of the developer asked me that he need a help in importing images into a table. It was interesting question for me as I never thought about the possibility of importing images to database table using a T-SQL. I invested some time and found that OPENROWSET is the solution which is the best way to open any non sql data sources.
--Target Table where data to be imported
CREATE TABLE userinfo
(
USER_ID INT NOT NULL IDENTITY(1, 1),
logonname VARCHAR(200),
profileimage VARBINARY(MAX)
) GO --Table to process the filesCREATE TABLE imagelist
(
imgfilename VARCHAR(200)
) GO --Put all file name in a table for easy processing
DECLARE @SQL AS NVARCHAR(2000) SET @SQL =N'xp_cmdshell ''dir d:\USerprofileImage /B''' INSERT INTO imagelist (imgfilename) EXEC sp_executesql @SQL
GO
--Import data into target table
DECLARE @SQL AS NVARCHAR(2000) DECLARE @ImgFilename AS VARCHAR(200) DECLARE filelist CURSOR FOR
SELECT imgfilename
FROM imagelist OPEN filelist FETCH NEXT FROM filelist INTO @ImgFilename WHILE ( @@FETCH_STATUS = 0 )
BEGIN
SET @SQL = 'insert into UserInfo(LogonName,ProfileImage)
select
reverse(substring(REVERSE('''+@ImgFilename +''') ,charindex(''.'',REVERSE('''+@ImgFilename+''' ),1)+1,LEN('''+@ImgFilename+'''))) ,
(SELECT img.bulkcolumn FROM OPENROWSET(BULK ''d:\USerprofileImage\'+@ImgFilename +''',SINGLE_BLOB) AS img)'
EXEC sp_executesql @SQL
FETCH next FROM FileList INTO @ImgFilename
END
CLOSE filelist DEALLOCATE filelist
GO--Drop the worktable
DROP TABLE imagelist
Thank you for this valuable information. The information you shared is very interesting. Get your business to the next level in simple steps. We provides lowest price of erp software Software for our clients.
ReplyDeleteerp software in chennai | erp providers in chennai | online events registration
Interesting post! This is really helpful for me. I like it! Thanks for sharing!
ReplyDeleteseo lüdenscheid
Hello there,
ReplyDeleteam looking for a solution where i can read characters or integers from a JPG image(taken by android camera) and i read these into some sort of table or database like excel, MS Access, SQL or equivalent..
i saw some OCR options on the internet but these do not seem to address what i want to achieve..
Exceptionally valuable information.
ReplyDeleteGreat Article
ReplyDeleteIEEE Projects for Engineering Students
Final Year Projects for CSE
ReplyDeletezapya for windows
zapya pc
zapya apk download
zapya free download
Great.. Tutorial is just awesome..It is really helpful for a newbie like me.
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to article very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
DedicatedHosting4u.com
thanks for sharing such a wonderful information from this post
ReplyDeletedigital marketing
kingroot for pc
ReplyDeletekingroot pc
download kingroot pc
kingroot apk
kingoroot
kingroot download
We don’t say Kingroot does that, but it’s kind of unknown and that’s what makes the app vulnerable
Vivo IPL 2020 Schedule
ReplyDeleteVivo IPL 2020 Fixtures
Vivo IPL 2020 Timetable
Vivo IPL 2020 Schedule download
Vivo IPL 2020 Fixtures download
Vivo IPL 2020 Timetable download
This is a great motivating content.I am fairly much happy with your great work.You put really very information
=https://mailsguide.com/aol-mail-sign-up-login
ReplyDeleteStill others are geared towards accessibility and cross-platform, mobile access