Converting TIMESTAMP To VARCHAR

Nov 23, 2006

CREATE FUNCTION dbo.fnTS2VC
(
@ts BINARY(8)
)
RETURNS VARCHAR(16)
AS
BEGIN
RETURNSUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 1, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 1, 1) AS TINYINT) % 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 2, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 2, 1) AS TINYINT) % 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 3, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 3, 1) AS TINYINT) % 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 4, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 4, 1) AS TINYINT) % 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 5, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 5, 1) AS TINYINT) % 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 6, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 6, 1) AS TINYINT) % 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 7, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 7, 1) AS TINYINT) % 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 8, 1) AS TINYINT) / 16, 1)
+ SUBSTRING('0123456789ABCDEF', 1 + CAST(SUBSTRING(@ts, 8, 1) AS TINYINT) % 16, 1)
ENDCall with

SELECT dbo.fnTS2VC(@@DBTS)

You can also use SELECT CAST(@@DBTS AS BIGINT) if you only need to convert the TIMESTAMP value to INTEGER.


Peter Larsson
Helsingborg, Sweden

View 4 Replies


ADVERTISEMENT

Converting Timestamp To Varchar Or Concatenating It With A String

Sep 20, 2007

Hello,

I apologise if this question has been asked before but I have searched forums and the web and have not found a solution. I am current creating a script that has a cursor that builds a sql statement to be executed e.g.

--code within cursor

SELECT '
DECLARE @Result INT
EXEC @Result = DELETE_DOCUMENT
@DocumentID = ' + STR(DocumentID) + ',
@TimeStamp =' + CAST([Timestamp] as varchar) + ',

-- CHECK RESULT AND STATUS
-- IF OK LOG IN META_BATCH ELSE LOG ERROR' AS SQL
FROM Document



The problem I am having is trying to join the timestamp column into the sql string. I have tried to cast the time stamp to a varchar but I end up with the following output for the timestamp column values

T
T€‘
T­
xnÞ
T!
T"
T#
T$
T%
T&
T'
T(
T)
T*
T+
T,

instead of


0x0000000013540F1C
0x0000000013540F1E
0x0000000013540F1F
0x0000000013786EDE
0x0000000013540F21
0x0000000013540F22
0x0000000013540F23
0x0000000013540F24
0x0000000013540F25
0x0000000013540F26
0x0000000013540F27
0x0000000013540F28
0x0000000013540F29
0x0000000013540F2A
0x0000000013540F2B
0x0000000013540F2C


which would not allow my delete script to work correctly. So I would really appreciate some advice to a pointer to where I might find out how to convert the timestamp.

Thanks
Sam

View 3 Replies View Related

Error While Converting Oracle Timestamp To Sql Server Timestamp (datetime) - Invalid Date Format

Jun 19, 2007

I am populating oracle source in Sql Server Destination. after few rows it fails it displays this error:

[OLE DB Destination [16]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005 Description:
"Invalid date format".



I used this script component using the following code in between the adapters, However after 9,500 rows it failed again giving the same above error:








To convert Oracle timestamp to Sql Server timestamp

If Row.CALCULATEDETADATECUST_IsNull = False Then

If IsDate(DateSerial(Row.CALCULATEDETADATECUST.Year, Row.CALCULATEDETADATECUST.Month, Row.CALCULATEDETADATECUST.Day)) Then

dt = Row.CALCULATEDETADATECUST

Row.CALCULATEDETADATECUSTD = dt

End If

End If



I don't know if my code is right . Please inform, how i can achieve this.

View 6 Replies View Related

Timestamp To VARCHAR Conversion (URGENT)

Jun 14, 2002

I need to pass a timestamp value to a varchar variable.CAST/Convert doesn't seem to help.

Any other work around ?

Thanks in advance.

View 1 Replies View Related

Converting DB2 Timestamp Data To SQL Server 2005 - Problems With Unique Index

May 24, 2007

I am attempting to move a timestamp data column from DB2 to SQL Server 2005. Normally not a big deal but the column is part of unique index.



The DB2 timestamp has seconds of ss.ssssss but SQL Server only has ss.sss.



Most all the times entered into this column are a from an automated process so they are really close together timewise.



Here is what I have come up with so far:

1. Fast Load OLEDB with a batch of 10,000 records at a time

2. On the fail of the batch redirect rows to a regular table load OLEDB insert task

3. On the fail of the single insert redirect rows to script that ups the seconds one tick.

4. Attempt one last insert of the modified rows

5. If fail, then store the record off to a delimited text file



I am hoping to get the number of records that wind up in the delimited text file to be a very small number and not in the 1,000+.



Any help would be appreciated.

View 5 Replies View Related

Converting 7 (int) To '07' (varchar)

Oct 29, 2004

Hi,

I'm converting a query from Access to SQL Server.

In this query I select from a column that contains numbers, the result I want is a varchar that is always 2 chars wide..

Ie:
7 should be selected as '07'
12 should be selected as '12'

In the Access-query it's rather nicely done with:
Format(Str(mycolumn),"00")

I could not find a way to make CONVERT do the same job... but I found that:
LEFT('00',2-LEN(CAST(mycolumn as varchar)))+CAST(mycolumn as varchar)
will do the job.

But it feels like it could be done nicer.. any suggestions?

View 2 Replies View Related

Converting The Varchar Value '52.91'

Mar 18, 2007

Hi,
I am trying ot do a count with a clause like this "amtdue >=10000 and amtdue <=25000" --- I get and error that says "Syntax error converting the varchar value '52.91' to a column of data type int" There are 20 million records in the table - this field is formatted as a varchar - can someone help me find the problem?

Thanks

John

View 3 Replies View Related

Converting Varchar To Int

Feb 28, 2008

hi all.

in my database i have two fields ..aprsal and datatype is varchar(100)
second field is maysal datatype is varchar(100)

i want to add these values after converting in to the int

how can i do this in sql

View 3 Replies View Related

Converting A Varchar To Int

Dec 12, 2006

I am struggling with converting a certain varchar column into an int.I have a table that has 2 fields - one field holds the loan number andthe other field holds the codes associated with that loan number.Here's some example data:Loan# Codes11111 24-13-122222 133333 2-9I need to check the Codes field for certain code numbers. The Selectstatement I'd like to use is:SELECT Loan#FROM Table1 WHERE Codes IN (2, 13, 1)/*My desired results is that all loans from the above example would beselected because they all have one of these codes*/Of course I cannot use the above statement because the Codes field is avarchar. And if I put single quotes around the numbers in my INstatement I don't get the desired results; the fields with multiplecodes are excluded.But how do I convert this varchar to an int? A simple convert or caststatement doesn't work. I've looked all over the web to find how to dothis, but have not been able to figure it out. Any help would be muchappreciated.

View 5 Replies View Related

Converting Varchar To Int

Apr 5, 2007

Syntax error converting the varchar value '3.1.7.4.3.9.' to a column of data type int...

how to overcome this problem ..



View 6 Replies View Related

Converting Int. To Varchar

Aug 20, 2007

I wrote a query that takes the field from one record and compares it to a different field in a different record. When I did it in access it worked. But I did a copie and paste into management studio and it is not working.

SELECT A.TRAN_ID, B.REFERENCE_DATA
FROM dbo.BSTRN_HEADER AS B LEFT OUTER JOIN
dbo.BSTRN_HEADER AS A ON B.REFERENCE_DATA LIKE A.TRAN_ID &'RECL'

I get the following error message:

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'RECL' to data type int.

So then I try:

SELECT A.TRAN_ID, B.REFERENCE_DATA
FROM dbo.BSTRN_HEADER AS B LEFT OUTER JOIN
dbo.BSTRN_HEADER AS A ON B.REFERENCE_DATA LIKE cast(A.TRAN_ID as varchar) & 'RECL'

I get the following error
Msg 402, Level 16, State 1, Line 1
The data types varchar and varchar are incompatible in the boolean AND operator.

Tran_id is an integer and reference data is a varchar and I need to convert tran_id to a Varchar

View 12 Replies View Related

Converting Varbinary To Varchar

Jun 23, 2005

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. 

any ideas ??

View 1 Replies View Related

Converting Ntext To Varchar

Aug 28, 2000

Is it possible to convert from ntext to varchar or text??
This is the syntax: ALTER TABLE ssu ALTER COLUMN analysis varchar NULL. This is the error message
Server: Msg 4928, Level 16, State 1, Line 1
Cannot alter column 'ANALYSIS' because it is 'ntext'. Thanks in advance!

View 2 Replies View Related

Converting Varchar Into Date

Aug 14, 2007

Hi
I have a table named prodwin in which i have to update a column name mfgdt which is varchar(10) to 7 months which I am able to do but the problem is that since it is only 10 character it is cutting the end of the year for eg

Before the date was
5/22/2000

UPDATE PRODWIN_MM SET MFGDT = DATEADD(MM,7,MFGDT)

Now it is this

Dec 23 200

Please tell me what to do , should i use cast or convert ?

Thanks in Adv

View 7 Replies View Related

Converting Varchar To Float

Aug 22, 2007

Hi all,

I'm trying to update a table as follows:
Where in the table i got.
OldCol; a varchar
NewCol; Float


Update tbl set newCol = cast(float,oldcol)
Where isNumeric(oldcol) =1

But it give me the follwong error:
Error converting data type from Varchar to Float.

Any suggestion?

View 12 Replies View Related

Converting Date To Varchar

Jan 22, 2008

Hi all I would like anyone to help I want 2 convert a datetime to 2008-02-02 21:00 the output must leave the time just 2008-02-02


If (@DateCreated <> 0)
Begin
Set @varSelectSql = @varSelectSql + ' And convert(varchar(10),DateCreated,121) = '+ cast(@DateCreated as varchar(10))
End

View 4 Replies View Related

Converting Varchar To DateTime

Sep 17, 2007



Hi,

I wanted to convert the varchar to date time and here is what i am doing


DECLARE @dt VARCHAR(20)

SET @dt = '20070111' -- YYYYMMDD format

select CONVERT(datetime, @dt, 120)


This works perfectly fine and the result would be- 2007-01-11 00:00:00.000

But if i changed my datetime format from YYYYMMDD to YYYYMMDDHHMM then this is failing and throwing

"Conversion failed when converting datetime from character string."

Can any one please let me know how do we achieve this?



~Mohan

View 3 Replies View Related

Converting Varchar To Datetime

Oct 23, 2007



Hi,


I'm facing a small issue with date conversions. It would have been great if someone could help me out. I have a field in my database (SQL Server 2000) called SavDateTime of type varchar(50). I store dates in this field in the format "dd/MM/yy hh:mms". A sample date would be "23/10/2007 10:15:30 AM". Now I need to have an order by for this field, say like,


select * from sample order by SavDateTime desc


When I execute this query I get an error saying "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.". I tried using the convert method also like CONVERT(DATETIME,SavDateTime,103), but the problem still exists. It would have been helpful if you could provide me with a solution to this problem.



Thanks & Regards,
Frens

View 7 Replies View Related

Conversion Failed When Converting The Varchar Value

Aug 2, 2007

why do i have this error? not converting a varchar into int 1 ALTER PROCEDURE dbo.RevertDB
2 (
3 @Log varchar(MAX) = NULL OUTPUT
4 )
5
6 /* Reverts Database to original "Clean" State */
7 AS
8 SET NOCOUNT OFF
9 DECLARE @RowsInDB AS int
10 SET @Log = 'RevertDB Started at ' + CAST(GETDATE() AS varchar(50)) + '<br />'
11
12 /* *** Disable Constraints ***
13 ALTER TABLE Booking NOCHECK CONSTRAINT ALL
14 ALTER TABLE InventoryPC NOCHECK CONSTRAINT ALL
15 ALTER TABLE PC NOCHECK CONSTRAINT ALL
16 ALTER TABLE Platform NOCHECK CONSTRAINT ALL*/
17
18 /* *** Start Deletes *** */
19 DELETE FROM Booking
20 SET @Log = @Log + 'Clear Table Booking - Done' + '<br />'
21 SET @RowsInDB = (SELECT COUNT(BookingID) FROM Booking)
22 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
23
24 DELETE FROM InventoryPC
25 SET @Log = @Log + 'Clear Table InventoryPC - Done' + ''
26 SET @RowsInDB = (SELECT COUNT(InventoryID) FROM InventoryPC)
27 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
28
29 DELETE FROM PC
30 SET @Log = @Log + 'Clear Table PC - Done' + '<br />'
31 SET @RowsInDB = (SELECT COUNT(PCID) FROM PC)
32 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
33
34 DELETE FROM Platform
35 SET @Log = @Log + 'CLear Table Platform - Done' + ''
36 SET @RowsInDB = (SELECT COUNT(PlatformID) FROM Platform)
37 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
38
39 /* *** Enable Constraints ***
40 ALTER TABLE Booking WITH CHECK CHECK CONSTRAINT ALL
41 ALTER TABLE InventoryPC WITH CHECK CHECK CONSTRAINT ALL
42 ALTER TABLE PC WITH CHECK CHECK CONSTRAINT ALL
43 ALTER TABLE Platform WITH CHECK CHECK CONSTRAINT ALL*/
44
45 SET @Log = @Log + '*** End Truncates ***' + '<br />'
46 /* *** End Truncates *** */
47
48 /* *** Start Insert Platform *** */
49 SET @Log = @Log + 'Start Insert Platform' + '<br />'
50
51 EXEC dbo.InsertPlatfrom 'Windows XP SP2 Professional Edition', 'Some description for Windows XP SP2 Professional Edition over here …'
52 EXEC dbo.InsertPlatfrom 'Windows Vista Ultimate', 'See everything you''re working on more clearly with Windows Aero, and quickly switch between windows or tasks using Windows Flip 3D and Live Thumbnails. You can easily find what you need—when you need it―with Instant Search and live icon previews that display the actual contents of your files. And while you''re at it, give your personal productivity a boost with instant access to the information you care about using Windows Sidebar and Gadgets. Put these easy-to-use and customizable mini-applications on your desktop and reveal the information you''re looking for at a glance. Website: http://www.microsoft.com/windows/products/windowsvista/seeit/default.mspx'
53 EXEC dbo.InsertPlatfrom 'Apple Mac OS X Tiger', 'Some description for Apple Mac OS X Tiger over here …'
54 EXEC dbo.InsertPlatfrom 'Apple Mac OS X Leopard', 'Desktop: The new look of Leopard showcases your favorite desktop image and puts new file Stacks at your fingertips for a stunning, clutter-free workspace. Finder: Browse your files like you browse your music with Cover Flow. Time Machine: See how your system looked on any given day and restore files with a click. Website: http://www.apple.com/macosx/leopard/features/'
55 EXEC dbo.InsertPlatfrom 'Red Hat Linux', 'Some description for Red Hat Linux over here …'
56
57 SET @Log = @Log + 'Rows In Platform: ' + CAST((SELECT COUNT(PlatformID) FROM Platform) AS varchar(10)) + '<br />'
58 /* *** Start Insert PC *** */
59 SET @Log = @Log + 'Start Insert PC' + '<br />'
60
61 DECLARE @WinXP int, @WinVista int, @OSXTiger int, @OSXLeopard int, @RedHat int
62 SET @WinXP = (SELECT PlatformID FROM Platform WHERE Title = 'Windows XP SP2 Professional Edition')
63 SET @WinVista = (SELECT PlatformID FROM Platform WHERE Title = 'Windows Vista Ultimate')
64 SET @OSXTiger = (SELECT PlatformID FROM Platform WHERE Title = 'Apple Mac OS X Tiger')
65 SET @OSXLeopard = (SELECT PlatformID FROM Platform WHERE Title = 'Apple Mac OS X Leopard')
66 SET @RedHat = (SELECT PlatformID FROM Platform WHERE Title = 'Red Hat Linux')
67
68 EXEC dbo.InsertPC 'Fusion PC One', 'Description here ...', 'Intel Core2 Duo E6600 2.4 GHz 1066MHz', '1GB Dual Channel DDR2 667 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3', '22" 3000:1 Wide Screen LCD', @WinXP
69 EXEC dbo.InsertPC 'Fusion PC Two', 'Description here ...', 'Intel Core2 Duo E6850 3 GHz 1333MHz', '2GB Dual Channel DDR2 800 SDRAM', '240GB SATA2 NCQ HDD', 'NVIDIA GeForce 8800 Ultra 256MB GDDR3 SLI', '24" 3000:1 Wide Screen LCD', @WinVista
70 EXEC dbo.InsertPC 'Fusion PC Three', 'Description here ...', 'AMD Athlon 64 X2 Dual Core 6000+ 3 GHz', '2GB Dual Channel DDR2 667 SDRAM', '240GB SATA2 NCQ HDD', 'ATI Radeon Cross Fire 2900 256MB GDDR3', '24" 3000:1 Wide Screen LCD', @WinVista
71 EXEC dbo.InsertPC 'Fusion X1', 'Description here ...', 'Intel Core2 Extreme Q6850 3 GHz 1333MHz', '6GB Dual Channel DDR2 800 SDRAM', '500GB SATA2 NCQ HDD', 'NVIDIA GeForce 8800 Ultra 256MB GDDR3 SLI', '30" 3000:1 Wide Screen LCD', @OSXLeopard
72 EXEC dbo.InsertPC 'Fusion X2', 'Description here ...', 'AMD Athlon 64 FX 74 3 GHz', '6GB Dual Channel DDR2 800 SDRAM', '500GB SATA2 NCQ HDD', 'NVIDIA GeForce 8900 Ultra SLI 256MB GDDR3', '30" 3000:1 Wide Screen LCD', @WinVista
73 EXEC dbo.InsertPC 'Fusion Tiger 1', 'Description here ...', 'Intel Core2 Duo E6600 2.4 GHz 1066MHz', '2GB Dual Channel DDR2 800 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3 SLI', '22" 3000:1 Wide Screen LCD', @OSXTiger
74 EXEC dbo.InsertPC 'Fusion Linux 1', 'Description here ...', 'AMD Athlon 64 X2 6000+ 3 GHz', '1GB Dual Channel DDR2 800 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3', '22" 3000:1 Wide Screen LCD', @RedHat
75
76 SET @Log = @Log + 'Rows In PC: ' + CAST((SELECT COUNT(PCID) FROM PC) AS varchar(10)) + '<br />'
77
78 /* *** Start Insert Inventory *** */
79 SET @Log = @Log + 'Start Insert Inventory' + '<br />'
80
81 DECLARE @F1 int, @F2 int, @F3 int, @FX1 int, @FX2 int, @FT1 int, @FR1 int
82 SET @F1 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC One')
83 SET @F2 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC Two')
84 SET @F3 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC Three')
85 SET @FX1 = (SELECT PCID FROM PC WHERE Title = 'Fusion X1')
86 SET @FX2 = (SELECT PCID FROM PC WHERE Title = 'Fusion X2')
87 SET @FT1 = (SELECT PCID FROM PC WHERE Title = 'Fusion Tiger 1')
88 SET @FR1 = (SELECT PCID FROM PC WHERE Title = 'Fusion Linux 1')
89
90 EXEC dbo.InsertInventory 10, @F1, 2.5, 'iCluster Fusion One'
91 EXEC dbo.InsertInventory 10, @F2, 2.5, 'iCluster Fusion Two'
92 EXEC dbo.InsertInventory 10, @F3, 2.5, 'iCluster Fusion Three'
93 EXEC dbo.InsertInventory 6, @FX1, 6, 'iCluster Fusion X1'
94 EXEC dbo.InsertInventory 6, @FX2, 6, 'iCluster Fusion X2'
95 EXEC dbo.InsertInventory 10, @FT1, 3, 'iCluster Fusion Tiger One'
96 EXEC dbo.InsertInventory 30, @FR1, 2, 'iCluster Fusion Linux One'
97
98 SET @Log = @Log + 'Rows In Inventory: ' + CAST((SELECT COUNT(InventoryID) FROM InventoryPC) AS varchar(10))
99
100 RETURN @Log
  if i remove the last line then all is well. but i get "An SqlParameter with ParameterName '@Log' is not contained by this
SqlParameterCollection."

View 2 Replies View Related

Error Converting Varchar To Numeric

Nov 18, 2003

i have a huge stored procedure abt 500 lines..and i am calling this sp from an asp.net page...thn i got this error - error converting varchar to numeric - and am trying to debug...is there any way we can find out where the error is coming from...like aproxly which line number..etcor do i have to go through each line manually and see where i am doing the conversion....

thanks

View 2 Replies View Related

Converting Varchar To Date From Asp.net To Sort

Jul 20, 2004

for some odd reason our other programmer used varchar datatype to store dates. he claims it gives him more control. now i am trying to sort it based on date. so i create a procedure:

CREATE PROCEDURE GetAllWeekEnding

AS
Select convert(datetime, we) as we2 FROM tblArchive order by we2
GO

if i use the convert function in the procedure, i'll get an error msg when i run the code. this is the code i am using.

Dim MyConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringSQL"))
Dim MyCommand As SqlCommand

MyCommand = New SqlCommand("GetAllWeekEnding", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure
MyConnection.Open()

Dim mydr As SqlDataReader = MyCommand.ExecuteReader()
While mydr.Read()
DropDownList1.Items.Add(mydr("we2"))
End While

mydr.Close()
MyConnection.Close()

the error message is: No accessible overloaded 'ListItemCollection.Add' can be called without a narrowing conversion

any ideas?

View 5 Replies View Related

Syntax Error Converting The Varchar Value

Nov 4, 2004

Hey gurus!
I've got a stored proc I call to obtain user info from a table. I've used the same format (but is slightly different) for another stored proc which works. But this one gives me "Error: System.Data.SqlClient.SqlException: Syntax error converting the varchar value 'SELECT User_UserName AS Username, User_LastLogin AS LastLogin, User_DateCreated AS Created FROM Community_Users WITH(nolock) WHERE (User_CommunityID = '' to a column of data type int. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteReader() at ASP.Recent_Logins_ascx.BindGrid() at ASP.Recent_Logins_ascx.Page_Load(Object Src, EventArgs e) :"

Why is this stored proc converting my SQLStatement to type int???

Here's my stored proc:

CREATE PROCEDURE Community_RecentLogins
(
@CommunityID int,
@SortField nvarchar(75)
)
AS

-- Create a variable @SQLStatement
DECLARE @SQLStatement varchar(255)
SELECT @SQLStatement = 'SELECT User_UserName AS Username, User_LastLogin AS LastLogin, User_DateCreated AS Created FROM Community_Users WITH(nolock) WHERE (User_CommunityID = ''' + @CommunityID + ''') ORDER BY ' + @SortField

-- Execute the SQL statement
EXEC(@SQLStatement)


And here's the (relevant) code in the ascx:

Sub BindGrid()
Dim conPortal as SqlConnection = New SqlConnection(CommunityGlobals.ConnectionString)
Dim cmdGet as SqlCommand = new SqlCommand("Community_RecentLogins", conPortal)
cmdGet.CommandType = CommandType.StoredProcedure
cmdGet.Parameters.Add("@CommunityID", CommunityGlobals.CommunityID)
If SortField = String.Empty Then
cmdGet.Parameters.Add("@SortField", "User_LastLogin DESC")
Else
cmdGet.Parameters.Add("@SortField", SortField & " DESC")
End If
conPortal.Open()
Dim dr as SqlDataReader = cmdGet.ExecuteReader()
LoginGrid.DataSource = dr
LoginGrid.DataBind()
conPortal.Close()
End Sub

Property SortField() As String
Get
Dim o As Object = ViewState("SortField")
If o Is Nothing Then
Return String.Empty
End If
Return CStr(o)
End Get
Set(ByVal Value As String)
ViewState("SortField") = Value
End Set
End Property


Any help is appreciated! Thanks in advance...

View 2 Replies View Related

Conversion Failed When Converting The Varchar Value ...

Dec 6, 2006

I am trying to have the aggregate value 1 replaced by 'only one' in my results.

My data looks like this:


Customer_id (int) ; Salesperson_id
1 ; 1
2 ; 1
3 ; 1
4 ; 2
5 ; 2
6 ; 3


...this is the solution I tried:


select
case when count(convert(varchar(15), customer_id)) = 1
Then 'only one customer'
else count(convert(varchar(15), kund_id)) end as no_of_customers,
salesperson_id
from customerdb
group by
salesperson_id

...and this is the result I was hoping for


no_of_customers ; salesperson_id
3 ; 1
2; 2
only one customer;3


...but SQL server only returns: Conversion failed when converting the varchar value ...

View 1 Replies View Related

Converting A Binary/hexadecimal To Varchar

Feb 25, 2004

How should I convert a binary/hexadecimal value to Varchar

Thanks in Advance,
Jake

View 1 Replies View Related

Converting From Varchar To Double Or Integer

Apr 3, 2008

Haiii..

I save number in database as varchar, but i want to call it back and
convert as double/int. Can it be done

View 13 Replies View Related

Conversion Failed When Converting Varchar To Int

May 26, 2008

Hi guys,



My query was working fine until I added the red writing below.

Basically what I'm doing with this is getting the lowest open purchase order number (docnum) and its matching docduedate.

Now when I run it I get

Conversion failed when converting the varchar value 'po_num' to data type int.



Any ideas? Thanks!



SELECT t3.product ,

t7.itemname ,

t2.u_vlgx_plc,

t3.shorted ,

t4.onhand ,

MIN(

CASE

WHEN t8.linestatus = 'O'

THEN t9.docnum

ELSE NULL

END) po_num,

t10.docduedate





FROM

(SELECT t0.product product ,

SUM(

CASE

WHEN t0.qty_topick <> t0.qty_picked

THEN t0.qty_topick - t0.qty_picked

ELSE 0

END) shorted

FROM rbeacon.dbo.shipline2 t0

INNER JOIN rbeacon.dbo.shiphist t1

ON t0.packslip = t1.packslip

WHERE t1.date_upld = CONVERT(VARCHAR(10), GETDATE()-1, 101)

GROUP BY t0.product

) t3

INNER JOIN comparison.dbo.vlgxplc t2

ON t2.itemcode = t3.product COLLATE Latin1_General_CI_AS

LEFT JOIN

(SELECT t0.product AS product,

SUM(t0.quantity) AS onhand

FROM rbeacon.dbo.binlocat t0

GROUP BY t0.product

) t4

ON t3.product = t4.product

INNER JOIN wbau.dbo.oitm t5

ON t3.product = t5.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS

LEFT JOIN wbau.dbo.ocrd t6

ON t5.cardcode = t6.cardcode

INNER JOIN wbau.dbo.oitm t7

ON t3.product = t7.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS

LEFT JOIN wbau.dbo.por1 t8

ON t3.product = t8.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS

LEFT JOIN wbau.dbo.opor t9

ON t8.docentry = t9.docentry

LEFT JOIN comparison.dbo.podatetest('po_num') t10

ON t10.docnum = t9.docnum



WHERE t3.shorted <> 0

GROUP BY t3.product ,

t7.itemname ,

t2.u_vlgx_plc,

t3.shorted ,

t4.onhand ,

t6.cardname,

t10.docduedate

ORDER BY t2.u_vlgx_plc,

t6.cardname ,

t3.product

View 9 Replies View Related

Syntax Error Converting Varchar To Int.

Jun 13, 2008

Hello,

I have table1
ID PATH
1 .166.184.185.186.

Need get data from table2 using PATH data from table1
select * from table2 where id in (
select Substring(replace(path,'.',','),2,Len(path)-2) from table1)
ERROR:
Syntax error converting the varchar value '166,184,185,186' to a column of data type int.

Any solution please.

Regard,
M.Z.

View 2 Replies View Related

Converting Varchar To Numeric Values

Oct 31, 2005

Not sure how I can convert varchar to numeric values in SQL Server? Trying to do so in Design and get error:
Unable to modify table.
ODBC error: [Microsoft][ODBC Server Driver][SQL Server] Error converting data type varchar to numeric.
Any suggestions?

View 5 Replies View Related

Error Converting Varchar To Numeric. Where???

Dec 11, 2007

Im running a DTS package that converts data in a fixed width text file to SQL table. The package runs successfully, but when I go to dump 60,000+ records in the table I get this error:

"Error Converting data type varchar to numeric."

Is there a way that I can isolate where the offending values are located so I can manually correct them?

View 4 Replies View Related

Error Converting Varchar To Numeric

Jan 28, 2008

I am trying to change a value in a table. For instance the value is now 3. If I try to change the value to say 2 or 4 I get and error converting data type varchar to numeric. So wazzagoingon?

View 6 Replies View Related

Problems Converting Varchar To Smallmoney

Oct 11, 2006

Hi


My ticket engine stores values in varchar. The sql db-field that
corresponds was created as smallmoney.


The below statement works for conversion of "leavedays" if the given
value is entered without any decimal places (E.G. 4)


As soon as a user enters a value that includes decimal places (E.G.
4.5) the conversion will not work. In this case the value 4.5 is
rounded to 5.


What do i have to do to convert the value as it is entered by the user?


Thanks in advance


t.


Statement:


INSERT INTO leavereq (mitarbeiter, startdate, enddate, leavedays,
remainingdays, approvedby, approvedon) SELECT {0} , convert(datetime,
{1}) , convert(datetime, {2}), convert(numeric, {3}), convert(numeric,
{4}),{5}, getdate()


DDL for concerned database:


CREATE TABLE [dbo].[leavereq] (
[mitarbeiter] char(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[startdate] datetime NULL,
[enddate] datetime NULL,
[leavedays] smallmoney NULL,
[remainingdays] smallmoney NULL,
[approvedon] datetime NULL,
[approvedby] char(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
ON [PRIMARY]
GO

View 3 Replies View Related

Transact SQL :: Converting Varchar Into Different Format

Jun 22, 2015

I have a varchar(512) data type on my INVOICE_DATE field and it is in the following format DD/MM/YYYY.

I need it to be in MM/DD/YYYY and have tried with no luck.

SELECT CONVERT(VARCHAR(512), INVOICE_DATE, 101) AS [MM/DD/YY]
FROM F0AInvoices_Tags

This does not swap the numbers as I would have hoped for reporting purposes.

View 8 Replies View Related

Error Converting Data Type Varchar To Int.

Oct 9, 2007

can anyone see as to why I would get this error with the following SP?
 ALTER PROCEDURE [dbo].[SP]
@ID int = 0,
@emailFrom VARCHAR(50) = Null,
@emailDate VARCHAR(50) = Null,
@emailSubj VARCHAR(50) = Null,
@emailTxtBody VARCHAR(1000) = Null,
@emailHtmlBody VARCHAR(1000) = Null

AS
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @Notes VARCHAR (8000)
DECLARE @TicketID INT
DECLARE @emailBody VARCHAR (1000)
DECLARE @Length Int

SET @Notes = ''
SET @Length = LEN(@emailSubj)

-- insert a new entry
INSERT INTO PopEmail
( emailFrom, emailDate, emailSubj, emailTxtBody, emailHtmlBody )
VALUES
( @emailFrom, @emailDate, @emailSubj, @emailTxtBody, @emailHtmlBody )
-- get the new ID
SET @ID = @@identity

If ( @ID <> 0 ) AND ( ISNUMERIC(@emailSubj) = 1 )

Begin
IF @emailTxtBody IS NULL
BEGIN
Set @emailBody = @emailHtmlBody
PRINT '@emailHtmlBody: ' + @emailBody
END

ELSE

BEGIN
SET @emailBody = @emailTxtBody
PRINT '@emailTxtBody: ' + @emailBody
END

SET @TicketID = CAST( @emailSubj AS int )
SET @Notes = @emailFrom + ', ' + @emailDate + ', ' + @emailBody
Select @ID = ID From TicketDetails Where TicketDetails.TicketID = @TicketID

Exec differentSP @ID, @TicketID, @Notes

PRINT 'Subject: [' + @emailSubj + ']'
print 'length: ' + CAST(@Length as varchar (10))
Print 'emailSubj: ' + CAST( @emailSubj AS int )
PRINT 'ID: ' + Cast( @ID as varchar ( 10 ) )
PRINT 'TicketID: ' + Cast( @TicketID AS Varchar ( 10 ) )
PRINT 'Notes: ' + @Notes
PRINT 'ID: ' + Cast( @ID as varchar ( 10 ) )
END
ELSE

BEGIN
Print 'ID: ' + CAST(@ID AS VarChar(10))
PRINT 'ISNUMERIC: ' + CAST(ISNUMERIC(@emailSubj) AS VarChar (10))
PRINT 'Subject: [' + @emailSubj + ']'
END 

View 2 Replies View Related







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