Transact SQL :: To Convert Datatype For A Column

May 29, 2015

I am using SQL server 2008 .I have a table which has 1.5 crore records and some of my columns are Char datatype.Because of this i have spaces in my columns.Now I want to convert char to varchar datatype .But i have index on those columns .

View 2 Replies


ADVERTISEMENT

Transact SQL :: Based On Data Convert Datatype And Make Wrong Date As NULL

Apr 21, 2015

In the below scenario we are inserting some time related fields in Temp table.But its data type is varchar. Once data loading is finished in the temp table (Data is loading by source team SQOOP and they are unable to load if the source datatype is having Date or datetime) we have to alter the column datatypes. somehow, some character data in inserted in date columns (look at into 3rd insert statement). while altering the table it is failing. Can we do any alternative for this (Means if any varchar data that is non convertible to date can we make as null)

INSERT INTO ##TEMP_TEST
SELECT '2014-09-30','2017-10-06','Nov  6 2014  6:11AM','Nov  6 2014  6:11AM'
UNION SELECT '2014-09-29','2017-10-06','Nov  6 2014  6:11AM','Nov  6 2014  6:11AM'
UNION SELECT '2014-09-28','2017-10-06','Nov  6 2014  6:11AM','Nov  6 2014  6:11AM'
GO
INSERT INTO ##TEMP_TEST SELECT NULL,NULL,NULL,NULL 

[Code] ....

View 6 Replies View Related

How To Convert A Column Datatype From Varchar To Varbinary?

Feb 3, 2007

I have a password column that needs to be converted from varchar to varbinary. Can anybody provide me a proper CONVERT statement syntax for it?

View 12 Replies View Related

Transact SQL :: How To Convert Row To Column In Server

May 11, 2015

I have a store procedure , a want to convert table result from row to column .My store

CREATE PROC GET_FUNCTION @GROUP_ID CHAR(3)
AS
SELECT A.GROUP_MOD_ID, B.FUNCTION_MOD_NAME,A.ALLOW FROM
FUNCTION_GROUP A INNER JOIN FUNCTION_MOD B ON A.FUNCTION_MOD_ID=B.FUNCTION_MOD_ID
WHERE A.GROUP_MOD_ID=@GROUP_ID

And this is my result

Ok , i want to convert same. NOTE : Number of row is can more , G02   Add-Delete    1 , G02    Add-Edit    1 , ..etc. . I want it dynamic column follow row

GROUP_MOD_ID       Add      Edit      Delete       ABC       XYZ     etc....

G02                          1             1            0            0             1      

View 9 Replies View Related

Transact SQL :: Convert Varchar (max) Column Data

May 20, 2015

I have a column in table which stores the actual signature from the singature pad. In the table it is stored as varchar(max) datatype and sample data looks like below. Below data is the actual signature of the person.

CREATE
TABLE #test
([Signature]
VARCHAR(MAX))

[code]...

How do i decrypt this data so i can print actual signature on my report.

View 2 Replies View Related

Transact SQL :: How To Convert Row To Column With Rows Dynamic

May 21, 2015

I want to convert row to columns with rows dynamic. I have two table, I'll join them and get data. See at

Ok , I try convert rows to columns with PIVOT . i want the result as

GROUP_MOD_IDADDEDITDELETE
G02101

CREATE PROC GET_FUNC @GID CHAR(5)
AS
BEGIN
SELECT FUNCTION_MOD_NAME

[Code] ....

But it's error

Msg 156, Level 15, State 1, Procedure GET_FUNC, Line 13
Incorrect syntax near the keyword 'FOR'.

Note: Type of ALLOW is bit and rows FUNCTION_MOD_NAME is dynamic

View 2 Replies View Related

Convert Char Datatype To Datetime Datatype

Sep 17, 2003

Database is SQL Server 2000

I have a field in a table that stores date of birth. The field's datatype is char(6) and looks like this: 091703 (mmddyy). I want to convert this value to a datetime datatype.

What is the syntax to convert char(6) to datetime?

Thank you in advance.

View 1 Replies View Related

Convert A Datatype

Mar 14, 2006

i have table tt.it contains two fields one is ttno int,doj datetime . i want toconvert to datetime to varchar .how it is .... give me some examples

View 3 Replies View Related

Convert Datatype From Db2 To Sql

Jun 18, 2007

i am running a package which extracts result of count(x), count(y),sum(z) from db2(as400) servers

i want to store the result of all the three in a table to a column of datatype varchar(25).

can someone help me with the convert/cast function in db2 which i can include in the query.



something like : select cast(count(x) as varchar(25)) from lib.file

View 3 Replies View Related

Transact SQL :: Convert Certain Row Values To Next Column Values

Jul 9, 2015

I have a table with 2 columns and my source data looks like this..

PolicyNum   InsCode    

1ABC12          1001        
1ABC12          1002        
1ABC12          1003       
1ABC12          1004       
1ABC12          1005        

[Code] ....

My output should look like this..I need T-sql to get below output.

PolicyNum   InsCode1   InsCode2    

1ABC12             1001       1005       
1ABC12             1002       1006        
1ABC12             1003       1004       
1ABC20             1001       1005        

[Code] ...

Basically it's converting certain row values to new column. Every PloicyNum will have 1001 to 1006 Fixed InsCode values as a group.

Rule-1: InsCode value 1001 should always mapped to 1005   
            InsCode value 1002 should always mapped to 1006
            InsCode value 1003 should always mapped to 1004 

Rule-2: For a policyNum, If any Inscode value is missed from the group values 1001 to 1006, still need to mapped with corresponding values as shown in Rule-1

In the above sample data..

for PolicyNum - 1ABC20 , group values 1003,1006 are missing
for PolicyNum - 1ABC25 , group values 1002,1003,1004,1005,1006 are missing

Create Table sampleDate (PolicyNum varchar(10) not null, InsCode Varchar(4) not null)
Insert into Sample Date(PolicyNum, InsCode) Values ('1ABC12','1001')        

Insert into Sample Date(PolicyNum, InsCode) Values ('1ABC12','1002')       
Insert into Sample Date(PolicyNum, InsCode) Values ('1ABC12','1003')      

[Code] ....

View 14 Replies View Related

Convert T/F Char To Bit DataType

Jun 4, 2008

Hi all,
There are several columns called enabled with a char datatype in my database. One enabled column per table. These columns either have a value of T or F (true or false), depending on whether they're enabled or not. I want to change these columns to a bit datatype and insert the relevant value of true or false...
I guess the best way to do this is to add a new column to a table with a bit datatype, and based on the value in the current enabled column, insert TRUE or FALSE.
Anyone ideas on the best way to accomplish this?
Thanks.

View 4 Replies View Related

How To Convert Varchar Datatype To Int??

Jul 2, 2007

Hi all,

I am using a varchar datatype for PIN number to handle zero at start. Now i want to do mathematical calculation to encrypt the PIN so i need to convert that varchar datatype to int so that zero should not be discarted after conversion. i.e. 0123 and 123 must not be treated as same PIN.

Please kindly give me a way out. I am using RSA encryption.

Thanks in anticipation.

Haider Abbas.

View 5 Replies View Related

Will It Auto Convert Datatype???

Jul 23, 2005

When i do this statement:insert into table (cost) values ('2')cost column is a bigint datatype.will it auto convert the string 2 into integer 2???

View 1 Replies View Related

How To Convert Bit Datatype To Text

Mar 24, 2008

I have a number of bit datatypes ( Boat types: Cruiser, Sportfisher, Megayacht, Sailboat) that I would like to place in a text box and do away with the individual selections. For instance, some marinas cater to "Cruiser", "Megayacht" and "Sailboat" while others include the "Sportfisher" also and there are many other combinations of vessels. I am stumped at how to write a query that takes the existing "True" values for each boat type and places them in a text box in the form of
" Cruisers, Megayachts, Sailboats" .

Thanks in advance for possible solutions.

View 1 Replies View Related

How To Convert Varchar To Xml Datatype In Sql2005

Dec 26, 2007

Hi,
 I have a talbe with a column type varchar(8000). i am facing problems sometimes as it corsses the limit also have the problems with special characters. so i went through few articles and been advised to use xml datatype. but when i am changing comumn name from varchar (8000) to xml as: 
alter table tblStudentForm alter column FormDetails xml not null
 i am getting following error:
Msg 9400, Level 16, State 1, Line 1
XML parsing: line 46, character 402, unexpected end of input
The statement has been terminated.
 
Please any one can advice how to alter on this.
 
Thanks
Dilip.

View 3 Replies View Related

Convert Image Datatype To Varchar

Aug 28, 2005

I have a table Table1 which has a Col called "Msg" datatype image<binary>. Msg alreay has the plain text or RTF text as a image datatype (binary)If I execute the following query "Select Msg from Table1 where id =3" then this query is returning the following ASCII/Binary data.Msg = "0x7B5C727466315C616E73695C616E7369637067313235325C64656666305C6465666C616E67313033337B5C666F6E7474626C7B5C66305C6673776973735C66707271325C66636861727365743020417269616C3B7D7B5C66315C6673776973735C66707271325C666368617273657430204D6963726F736F667420"Can any body tell me how can I convert the above binary data to plain text from my query?Thanks for any reply.

View 1 Replies View Related

Datatype Convert Char To Numeric

Dec 31, 2003

Hi,

I read the topic from JROdden and this case is similiar but...

I got several varchar fields with
values like
1.2
1.3
... these I can covert with
select CONVERT(dec(5,2), fieldname) as fieldname

In fact I also solved undefined- and NULL-values with.
CONVERT(decimal(12, 2), CASE WHEN GESCHKOSTMAX IS NULL OR
GESCHKOSTMAX < '0' THEN '0' ELSE GESCHKOSTMAX END) as GESCHKOSTMAX,

But now there are values like
1,4 and these ones neither CONVERT nor CAST will handle.

I tried the
SELECT DISTINCT KMPAUSCHALE
FROM extr_INTFIRMA
WHERE (isnumeric(KMPAUSCHALE) = 1)

and get
0,40
0.25
0.30 and so on...

The error is:
[Microsoft][ODBC SQL Driver][SQL Server]Error converting datatype varchar to decimal. (or float or numeric (whatever I tried))

I think the easiest way would be to insist on higher data quality but
I also would like to solve this interesting challenge.


Thanks for any hints

By the way, I followed rudys link to
http://rudy.ca/afdb.html
and now I know how I could protect myself !!!!

There must be a voice in my head saying:
Try the db-forum, try it and stay happy... ;-)

best regards and have fun with new year eve.

Michael

View 8 Replies View Related

Does NULL Inherit A Datatype After Convert

Jun 16, 2015

i have a little confusion...

DECLARE @name varchar(30)
SET @name = NULL
SELECT ISNULL(CONVERT(DATE,@name),'')
Result: 1900-01-01

But..

DECLARE @name varchar(30)
SET @name = NULL
SELECT ISNULL(@name,'')

Does NULL inherit a datatype after convert?

View 7 Replies View Related

How To Convert Nvarchar Datatype To Float

May 16, 2008

Hi,

how to convert nvarchar datatype to float?

Regards
Prashant

View 10 Replies View Related

Convert Varchar To Datetime Datatype?

Jun 19, 2014

I have a column on my table with the varchar(50) datatype. The whole column has the value 2014-04-31

I want to Convert the varchar(50)datatype to datetime datatype.

The table name is called - dbo.pracs

the column name is - LastDatUpaded

View 6 Replies View Related

Convert Varchar Datatype To Datetime2

Oct 14, 2014

Need to fetch the date from parent table to chile table. This is the script ....

case When @AccountingDate IS NULL THEN NULL ELSE CONVERT (varchar,@AccountingDate , 101) END,
Case When @InventoryDate IS NULL THEN NULL ELSE CONVERT (varchar,@InventoryDate,101) END,
Case When @StatusDate IS NULL THEN NULL ELSE CONVERT (varchar,@StatusDate,101) END,
Case When @LastInstallmentDate IS NULL THEN NULL ELSE CONVERT (varchar,@LastInstallmentDate,101) END,
Case When @RetailFirstPayDate IS NULL THEN NULL ELSE CONVERT (varchar,@RetailFirstPayDate,101) END ,
Case When @LeaseFirstPayDate IS NULL THEN NULL ELSE CONVERT (varchar,@LeaseFirstPayDate,101) END ,
Case When @DayToFirstPayment IS NULL THEN NULL ELSE CONVERT (varchar,@DayToFirstPayment,101) END ,
Case When @EntryDate IS NULL THEN NULL ELSE CONVERT (varchar,@EntryDate,101) END ,
Case When @DealBookDate IS NULL THEN NULL ELSE CONVERT (varchar,@DealBookDate,101) END ,
Case When @RealBookDate IS NULL THEN NULL ELSE CONVERT (varchar,@RealBookDate,101) END

View 6 Replies View Related

Convert Sting To Datetime Datatype

Jul 29, 2015

How to convert in MS SQL server 2005 from string to Datetime datatype

SELECT
[customer_key] ,
[company_code],
[distributor_code] ,
[dist_center],
[cust_code_ref] ,
[customer_name],

[Code] ....

Giving error:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

View 5 Replies View Related

Ho To Convert Varchar Datatype Into Datetime

Aug 22, 2007




declare @a varchar(10)
select @a= shiftstarttime from o_parameter
print @a

declare @b varchar(10)
select @b= shiftendtime from o_parameter
print @b


declare @dt varchar(20)
set @dt=Left(getdate(),12)

print @dt

declare @dt1 varchar(20)
set @dt1=Left(dateadd(dd, 1,getdate()),12)
print @dt1

declare @dt3 varchar(20)

set @dt3= @dt1 + space(0) + @a

print @dt3

declare @dt4 varchar(20)

set @dt4= @dt + space(0) + @b

print @dt4




output of above script is as fallow
09.30am
06.30pm
Aug 22 2007
Aug 23 2007
Aug 23 2007 09.30am
Aug 22 2007 06.30pm

now i want to convert @dt3 and @dt4 into datetime .

because i wnat to calculate datedifference in hours by using this function
SET @in_hour=DATEDIFF (HH ,@D1,@D2)

where @D1 and @D2 are datetime parameters.

but how can i get @dt3 and @dt4 into datetime so i can pass it to DATEDIFF() function.

so plz Guide me. or if u know how to write it then plz write here

i already use cast for it but it doesn't work.

so plz reply urgently.








View 2 Replies View Related

SQL 2012 :: How To Convert Image Datatype To String

Aug 4, 2015

I have an Image data which I need to convert to string data.

Tried "Select CAST(CONVERT(nchar(1000),CAST( body AS varBINARY(1000) )) as VARCHAR(1000)) as TD
FROM Table",

But it returns a set of question marks.

(ex: ????????????(?????????????????????†????????????????????????????????
???????????????????????????????????????????????8??????????????????...)

View 4 Replies View Related

Error When Convert Or Cast Functions From Varchar To XML Datatype

Dec 29, 2007

Hi I have a varchar(8000) and currently XML files are stored in varchar(8000).Some times when i am doing manuplactions in my varchar column i am getting with special characters error. so now i want to keep my column varchar(MAX) and when i am doing calculations i will convert my varchar datatype to xml datatype. By doing this i hope there wont be any special character problems.
When i am doing calculations with the wellformed xml i am getting error for both convert and cast methods as below 
I am trying to do convert(xml,MyVarcharColumn)
Implicit conversion from data type xml to nvarchar is not allowed. Use the CONVERT function to run this query.
Also i tried with casting and getting same problme. is there any way to convert
 
please suggest me
 
Thanks
Dilip

View 1 Replies View Related

Problem Convert Datatype &#39;hyperlink&#39; From Access To SQL-Server

Mar 27, 2000

Hi,
on a migration from access 97 to SQL Server 7.0 columns in access like 'hyperlink' are converted to datatype 'text' on the SQL Server 7.0. Now I miss the function in the access application I had before with fields like 'hyperlink'. Now I can't start e.g. a word document with a click and I have to type in the hyperlink manualy.
Does anyone had the same problem an possibly have a resolve?
Thanks.

Michael from Frankfurt, Germany

View 2 Replies View Related

Reporting Services :: How To Convert Int Datatype To Time Format In SSRS

Aug 20, 2015

How do we convert int datatype to "time format" like hh:mm:ss

ex:    123092   ( this 12  + 30 min + 92 sec)
       131137   ( 13 + 11 min + 37 sec)
       111747 ( 11 + 17 min + 47 sec)

View 5 Replies View Related

Integration Services :: Convert Field Of VARCHAR To INT Datatype In SSIS 2014?

Nov 17, 2015

I'm trying to convert a column in my source table of datatype varchar(6) to a column of datatype int in my destination. I tried using the Derived Column/Data Conversion transformations but none of them worked. So, I tried using the following C# (credits to the original poster) and getting an error during compilation.

Note: "MyCol" is the Input Column I've specified in the Script Component and "CleanCol" is the Output column I've specified as datatype [DT_I4].

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
int colOut = 0;
if (!Int32.TryParse(Row.MyCol, out colOut))
{
Row.CleanCol_IsNull = true;
} else {
Row.CleanCol = colOut;
}
}

The best overloaded method match for 'int.TryParse(string, out int)' has some invalid arguments

The other expression I've tried was:

ISNULL(MyCol) ? (dt_i4)"" : (dt_i4)MyCol

From the above code, you might have understood that the source field has some blank records as well in the MyCol field.

What is the best possible way to do the conversion from a String to Int or fixing the error from the above.

View 10 Replies View Related

Transact SQL :: Casting To Same DataType

Jun 10, 2015

Biz talk server executes every query twice, first with FMT only to get metadata.If metadata changed, it will produce error.Now, i have query like:

SELECT col1, col2, col3 INTO #tmp FROM dbo.myTable

How SQL decide the type of column in #tmp? Does it create column of the same type as it is in dbo.myTable or its decision is based on result?For example, col1 is varchar(20), but col1 in #tmp will be varchar(200) or even nVarChar.Col2 is INT, but result is for example low number(like, 1,2,3,) - is it possible that col2 in #temp table will be smallint or tinyint even if col2 in myTable is INT.If that is true one way to overcome that will be to explicitly CAST all columns to proper data type. Is there any performance impact of casting: CAST(col1 as VARCHAR(20)) if col1 is already varchar(20) in dbo.myTable?

View 9 Replies View Related

Transact SQL :: Changing Length Of Datatype?

May 20, 2015

I have a field in a table

FormID nvarchar(6)

i want to change the length of the datatype to nvarchar(8).

what is the best way to do with out dropping the table?

View 5 Replies View Related

Transact SQL :: Decrypt Timestamp Datatype

Jun 23, 2015

I have column which has timestamp datatype.in this column inserting date in encrypt format.

I want insert date format into that column.If it is not possible to insert date format while fetching (through select statement) want to decrypt format ( I mean date format).

View 6 Replies View Related

Cast/Convert Mmddyy In String To New DB_DATETIMESTAMP Column In Derived Column Transformation

Mar 5, 2007

Hi,
I have dates in "mmddyy" format coming from the sources and they are older dates of mid 80s like 082580 for instance.

When I cast it this way (DT_DBTIMESTAMP) Source_Date , It says ok but throws a runtime error.

When I hardcode a date in same format, (DT_DBTIMESTAMP) "082580" , It becomes red (an indication of syntax error) . Please note that we use double quotes in expressions in Derived Column Transformation; So an anticipation that using double quotes over single ones would be the syntax problem would be wrong.



Any help in this will sincerely be appreciated.


Thanks

View 7 Replies View Related

Column Datatype

Jan 9, 2005

Hi folks, need ur help.

I want to convert strings from a textfile and convert em to appropriate datatype for the destination columns, eg if i have a source value in string 11111 and the destination column is MONEY. I want to use CONVERT(functionretruningdatatype,'11111') in my insert statement.

Any guidance!



Howdy!

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved