SQL 2012 :: Converting From Table With Varbinary To Filetable
Feb 17, 2014
I have a very large database running in a production environment. The backup files are getting to be very difficult to manage. They are at 70gb as of now and growing at a rate of 10gb per month. This is due to document images being stored in the database in one table. I have read a little about a new feature in SQL Server 2012 called Filetable. Can we migrate to SQL Server 2012 and convert to the filetable structure, will this decrease the size of the backups? Would backup of the document images be taken care of by our nightly file system backups now?
What is the best approach that I can take for the below requirement.
I am designing a tool that basically stores the information of employees. Once a person joins any organization, they need to enter their personal details through this tool.
The basic information that a person is required to enter includes
Now to store the employee photo and their educational certificates, I wanted to know , what would be the right approach.
I have googled on this and came across the concept of Filetable in sqlsever 2012. But it behaves independent of other tables. How would I store employee details and have a reference to filetable that can store images and other docs in a physical location. Or is it a good way of storing images and docs in DB directly.
I am new to Full-Text Searches and FileTables. I am working on a resume search system. I created a FileTable and the Share which contains about 51,000 resumes in Word (DOC/DOCX), PDF and TXT formats that were copied over from our main file server. I followed the instructions on adding the Microsoft Filter Pack 2.0, and all searchable file types are listed in sys.fulltext.document_types.
I have a program that searches resumes by First and Last Name and/or E-mail Address. For a while, we thought it was working fine because we were getting hits, but then we noticed some Names and E-mail Addresses we new existed were not showing up in my CONTAINS queries -- but we verified the documents do exist and the Names exist in the File Name and inside the document along with the E-Mail address.
One example I'm working on now cannot find the First/Last Name with CONTAINS(name,"lastname") in a Word DOC file, but I can find the document using LEFT(name,5) = 'Smith'. It's a Word DOC file. For testing purposes, I opened the DOC file in Word, then used Save As to create a TXT and DOCX file within the same folder. Now, both of those are showing up in the CONTAINS but not the original DOC file.
I have a password field which is of varbinary. Since its a varbinary I cannot see the password in the database I only see hexadecimal values. Now my question is that how can I convert those hexadecimal values to string or varchar so I can read the password.
Hi Gurus, Here is my problem-: I have a field in the SQL 2005 database with type varbinary(50). Now when i enter value to this field, I enter a value for example 111111101. The reason to enter such a value in varbinary(50) type is, that this value is meant to grow, as each 1 and 0 in this value is a permission or right my user would have to various features of the web application, I am designing. Now when I open the table to see the data in the database, it shows as <Binary data>. But that's okay, as binary fields are mostly meant to store pictures, files etc. But when I read this value into my ASP.Net code using c#, the value as returned as 069F6BBD. After some research I realized that for decimal value 111111101, the hex value is 069F6BBD. All I need in my code is the same thing that I entered which is 111111101. Can someone guide me a lil bit. Thanks in advance.. VJ
I am using rowVersion to detect rows that need to be re-extracted for my ETL. The first step in the ETL is to get MIN_ACTIVE_ROWVERSION() from the database, as well as the rowVersion from the last successful ETL run. Both of these values are saved in variables in SSIS. Since SSIS doesn't have an associated data type, these values are converted to nvarchar(512) before getting sent to SSIS.
I'm now trying to create a stored procedure to grab the data out of the source system. The sproc takes RowVersionMin and RowVersionMax as input parameters. Those parameters are then converted to varbinary(max), and I use them in a query to select the appropriate rows.
When I run the sproc in SSMS, it runs without a problem. However, when I try to use the sproc as a data source in SSIS, I get the following error: "Error converting data type nvarchar to varbinary". Why SSIS has a problem with this, but SSMS does not? The sproc code looks like this:
ALTER PROCEDURE [dbo].[dw_DimComment_DataLoad] @RunType varchar(3), @RowVersionMin nvarchar(512), @RowVersionMax nvarchar(512) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
I have an Execute SQL Task that queries for the contents of a file (which is declared as a varbinary type). My SSIS package needs to write these contents into a temporary location, so what I do is that I pass the result into a System.Object variable. I then use that variable in a Script Task.
Problem is whenever I execute my script task and DirectCast or CType the variable to a string (which is what the contents of the file is), I get a "Conversion from type '_ComObject' to type 'String' is not valid."
I have a stored procedure in which we are deriving some flags. So, we used series of CASE statements.
For examples
CASE WHEN LEFT(CommissionerCode, 3) IN ('ABC','DEF',...) THEN 1 WHEN PracticeCode IN (.......) THEN 1 WHEN (CommissionerCode IN (.....) OR PracticeCode NOT IN (.....) OR .....) THEN 1 ELSE 0 END
I need to put these conditions in config table and generate dynamic sql.
What is the best way to do this? especially, 3rd condition with OR logic with multiple columns involved.
I have a table with raw scientific test results in a single field, some of which are over 25Mb field. I need to parse into the field to find and aggregate selected values from the field.
Table structure is CREATE TABLE [dbo].[Gxxx_Data]( [id] [uniqueidentifier] NOT NULL, [Status] [nvarchar](50) NULL, [GxxxItem_ID] [int] NULL, [Stats_Data] [varbinary](max) NULL, ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
[code]...
From which I need to parse and summarize the (Assembler) opcodes (MOV,CMPi, SHR etc...)I need to parse the large field [Stats_Data] to locate the target data.The internal result strings are delimited with Char(10), conservative counts are from 64k to over 100k lines in each record. Is there a way to parse the individual lines into another table (temp) that would be queried/regexed ?
I need to take a temporary table that has various times stored in a text field (4:30 pm, 11:00 am, 5:30 pm, etc.), convert it to miltary time then cast it as an integer with an update statement kind of like:
Update myTable set MovieTime = REPLACE(CONVERT(CHAR(5),GETDATE(),108), ':', '')
how this can be done while my temp table is in session?
I am trying to create a statement that will update many rows in a table with images, stored as varbinary(max), into a new column.
The path/file information is all stored in another table, but I can't find a way to update more than 1 at a time. Here is the statement that works for 1 row at a time:
update tblphotos set photo = (select BulkColumn from Openrowset( Bulk '\**servername**PropsImagesDon Giovanni 2002PropsHorses Guts 2.jpg', Single_Blob) as photo ) where photoseq = 27
but if I try to do something like this:
CREATE TABLE #temp (
photoSeq int,
photoLoc varchar(255),
photo varbinary(max)
)
INSERT #temp
select p.photoseq, f.fldlocation + p.photophyloc as files, (select BulkColumn from Openrowset( Bulk f.fldlocation + p.photophyloc, Single_Blob) as photo ) FROM txprops t join tblfolders f on t.fldlocation = f.fldseq join tblphotos p on p.photopropseq = t.propseq
begin tran
update a set photo = b.photo from tblphotos a join #temp b on a.photoseq = b.photoseq where a.photoseq = b.photoseq
select * from tblphotos order by photophyloc
commit tran drop table #temp
I get an error: Incorrect syntax near 'f'. I think this is because I can only put a path in beside BULK.
I have investigated BULK and bcp commands, but cannot find anything to satisfy this. I tried the DTS package route, but am not getting very far.
Hey all, I have a profile table for members of a website that allows them to upload an avatar for use throughout the site. I decided to add the option to just remove the avatar if they want to no longer use one at all and I am stuck. I am running an update statement against thier entire profile incase they change more then just removing thier avatar but of course when I try this statement. myCommand.Parameters.AddWithValue("@avatar", "") I get a conversion error, which makes sence. So what instead of "" do I need for code to just insert empty data to overwirte thier current avatar data. Any help would be great, thanks for you time.
Hey all, Another varbinary question. I am trying to move an image stored in a table varbinary(max) directly from one table to another programmatically. The rest of the data is just nvarchar(50) so I just use a T-SQL select statement in the code behind and feed all of the date into an SqlDataReader, I do this becuse there is some user interaction when the data is moved, so there may be some new values updated when transfering from one table to another, so once the old and possibly new data is stored in seperate variables then I use a T-SQL insert statement to move all of the data into the other table. Problem is I am not really sure how to handle the image data(varbinary(max)) to just do a straight up transfer from the one table to another. I get conversion errors when trying to handle the data as a string which makes sense. Not sure what to put for code examples since I really am stumped with this, but here is what is not working. Dim imageX As String SqlDataReader Code - imageX = reader("imageData") Insert code - myCommand.Parameters.AddWithValue("@imageData", imageX) Thanks in advance,
I tried samples of FileTable in SQL Server 2012 to store files in database. I have following questions.
1. When I right click on FileTable, and say Explore File Table Directory, I was taken to a directory. But if I search the same directory in my server/machine, the directory is not available.
2. Can I use some external server/disk as a directory for FileTable?
3. How easy is to use FileTables using .Net web applications?
My question is how i can save the first result in a temp_array (or table i dont know) so I can get the result and split up the results again with the delimiter ','.
Is there an easy way to convert Access Queries to SQL Views without doing it manually?I have used the Databse tool to migrate tables, but cannot see to find something similiar for queries.
I'm trying to go deeper into SQL Server's XML support. When looking at a recent forum post, I got curious to see if I could achieve the same result with XPath and FLOWR. Here's the data I'm working with:
select data.mynodes.value('@Name', 'varchar(50)') Name from #data cross apply myXMLData.nodes('/order/Product/Drops/Drop[@Number="1"]/Area') data(mynodes) Results: Name 43001PBOX
[Code] .....
Here's my first attempt at a FLWOR expression. Note that doesn't produce the same results.
select myXmlData.query(' for $drop in /order/Product/Drops/Drop for $Name in $drop/Area/@Name where $drop/@Number=1 return data($Name) ') from #data Results: 43001PBOX 43001R001 43001R002 43023PBOX 43023R001 43023R002 43031PBOX 43031R001
How to build a FLOWR-based query that produces the same result as the pure XPath one?
I am using a custom sql query to import data into Tableau. Problem is I need to change the varchar column data in SQL currently returning 18/01/2014 08:35:13 as a format into the date format 05/21/2014 3:55:51 PM before I can use it.
I have a column name DateofRecord and it is nvarchar type..all the values in this column are like this
"04/24/2013' "05/01/2014"...etc...
My requirement is to convert this column into Datetime ?
I tried so many ways using cast and convert functions like cast(dateofrecord,datetime) or like convert(datetime,replace(DateofRecord,'"','''')) ..it didnt worked..
SELECT ROUND ('6.465',2) --- result 6.46 and SELECT ROUND (6.465,2) --- result 6.47 with
It's because you're relying on an implicit conversion from a string to a decimal data type which SQL server will do to 2 decimal places by default...
Alright:
SELECT ROUND (CONVERT(DECIMAL(3,2),'6.465'),2) --- result 6.47 Now please explain this: SELECT ROUND('0.285',2) -- 0.28 SELECT ROUND(0.285,2) -- 0.29 SELECT ROUND (CONVERT(DECIMAL(3,2),'0.285'),2) --- result 0.29 The string value does not seem to be converted to decimal with 2 decimal places.
MS is on the safe side with mentioning the last digit is always an estimate But because the result of the estimate is always the same, I would like to know:
* how is a string value exactly implicitly converted?
* how exactly does the estimation work, that in case of doubt rounds a value up or off?
Within in Visual Studio 2012 solution, I have several projects, one of which is a Database project. I am defining several tables. The one in question is:
CREATE TABLE [dbo].[tblKppHierarchyPcl] ( [ID] NUMERIC(18,0) NOT NULL, [Name] VARCHAR(500), [PartStructureKey] NUMERIC(18,0) NOT NULL, [PartNumber] VARCHAR(500) NOT NULL, [ParentPartNumber] VARCHAR(500) NULL,
[code]...
Error SQL72014: .Net SqlClient Data Provider: Msg 245, Level 16, State 1, Line 76 Conversion.failed when converting the varchar value 'Coolant Quick Disconnect' to data type int.So it has a problem with inserting 'Coolant Quick Disconnect' into the Name column. The Name column is CLEARLY a varchar column but somehow it thinks it's an int column.
I have a lot of rows of hours, set up like this: 0745, 0800, 2200, 1145 and so on (varchar(5), for some reason).
These are converted into a smalldatetime like this:
CONVERT(smalldatetime, STUFF(timestarted, 3, 0, ':')) [this would give output like this - 1900-01-01 11:45:00]
This code has been in place for years...and we stick the date on later from another column.
But recently, it's started to fail for some rows, with "The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value".
My assumption is that new data being added in is junk. If I query for these values and just list them (rather than adding a column to convert them also) that's fine, of course. I've checked all the stuffed (but not yet converted - so 11:45 rather than 1145) output to see if it ISDATE(), and it is. There are no times with hours > 23 or minutes greater than 59 either.
If I add the CONVERT in, we see the error message. But here's the oddity, if I place all of the rows into a holding table, and retry the conversion, there is no error. It's this last bit that is puzzling me. Plus I can't see any errors in the hours data that would cause a conversion problem.
I've put the whole of this into a cursor to try to trap the error rows too, but all processes fine. Why would it fail if NOT in a cursor?
I have been trying to convert datetime but keep getting this error(Conversion failed when converting date and/or time from character string.It works just fine if I don't use execute sp_executesql,.
<code> DECLARE @tablename AS nvarchar(max) DECLARE @SQLQuery AS NVARCHAR(MAX) DECLARE @ParameterDefinition AS NVARCHAR(100) DECLARE @startdate datetime
I am working on a code that will convert the query output into a html query output. That is the output of the query will be along with html tags so that we can save it as a html file.
The stored procedure that i have used is downloaded from symantec website and is working fine. Below is the code of that stored procedure.
/****** Object: StoredProcedure [dbo].[sp_Table2HTML] Script Date: 12/21/2011 09:04:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_Table2HTML] ( @TABLENAME NVARCHAR(500), @OUTPUT NVARCHAR(MAX) OUTPUT,
[Code] ....
The code works fine and i am able to get the output with html tags. The problem occurs when i insert stylesheet in the code. I tried to enforce styles using a stylesheet for the table returned in my sql code, so that it will look good. below is the stylesheet code that i inserted between <head> and </head> tags.
If I run the procedure without the style sheet code, it works fine. but when i run the procedure with style sheet code i am getting the below errors.
Msg 105, Level 15, State 1, Line 98 Unclosed quotation mark after the character string '</table></body><'. Msg 102, Level 15, State 1, Line 98 Incorrect syntax near '</table></body><'.
[Code] .....
I checked the code and i am not able to find what is the mistake. I tried changing the quotation mark but it didn't worked.
I need to get this data into an SQL table in the following form so I can use it to further manipulate the data and update several other tables. I am thinking that UNPIVOT or CROSS APPLY might be the way to go, but am not sure how to code it.