473,508 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting nvarchar to int

219 New Member
I'm trying to convert a data type of nvarchar to an int data type, but I keep getting errors when I try.

Here's my latest try:
Expand|Select|Wrap|Line Numbers
  1. cast(convert(int,submitter) as int) as 'Submitter' 
Any thoughts on how I can do this?
Mar 10 '08 #1
5 31537
dmorand
219 New Member
I'm trying to convert a data type of nvarchar to an int data type, but I keep getting errors when I try.

Here's my latest try:
Expand|Select|Wrap|Line Numbers
  1. cast(convert(int,submitter) as int) as 'Submitter' 
Any thoughts on how I can do this?
Nevermind, it does work....it's coldfusion that's being dumb.
Mar 10 '08 #2
dmorand
219 New Member
Actually I'm wrong. Some of the values in the table are text, and some are numbers so the fields that have text in them are causing the query to crash.

Any idea on how to only retrieve the fields in the rows that have numerical values in them?
Mar 10 '08 #3
ck9663
2,878 Recognized Expert Specialist
Try something like:

Expand|Select|Wrap|Line Numbers
  1. select 
  2.       case 
  3.           when isnumeric(submitter) = 1 then 
  4.                   cast(submitter AS int)
  5.           else
  6.                   NULL
  7.      end
  8.  
  9. AS 'Submitter'
  10. from YourTable
  11.  
Just change the else part as necessary.

-- CK
Mar 10 '08 #4
dmorand
219 New Member
Try something like:

Expand|Select|Wrap|Line Numbers
  1. select 
  2.       case 
  3.           when isnumeric(submitter) = 1 then 
  4.                   cast(submitter AS int)
  5.           else
  6.                   NULL
  7.      end
  8.  
  9. AS 'Submitter'
  10. from YourTable
  11.  
Just change the else part as necessary.

-- CK
That's a good idea, thanks!
Mar 10 '08 #5
dmorand
219 New Member
That's a good idea, thanks!
Thanks it worked out perfectly!
Mar 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
38564
by: Justin Wong | last post by:
CREATE PROCEDURE dbo.Synchronization_GetNewRecords ( @item varchar(50), @last datetime ) AS SET NOCOUNT ON
3
37059
by: ree32 | last post by:
For a SQL statement in an Alias column I am am combing several columns. But I am having problems with one column as it is a smallint. I get this error Syntax error converting the nvarchar value...
1
4414
by: Andrew Baker | last post by:
this seems to be an SQL Server error but I cant work out how it is occuring. Itr is also after 3am and I cant keep working but need to demo by tomorrow. TIA. The code is: Private Sub...
4
1634
by: lemes_m | last post by:
Hello Everyone, I have problem with the combo box which needs to show two columns together: - Id (Int) - Article (Varchar) If I merge those columns like "Id + ' - ' + "Article" Access said...
3
2408
by: michael via SQLMonster.com | last post by:
Hi, I am trying to automate a SQL Trace via a stored procedure and a job. The job executes the stored procedure to start the trace and every 15 minutes, the job is supposed to stop the trace,...
4
12981
by: D. | last post by:
Hi, I'm starting a new application in java using JTDS jdbc driver (http://jtds.sourceforge.net) and SQLServer 2005 Express. I have to design the database from scratch and my doubt is if I have to...
2
2999
by: Curious Trigger | last post by:
Hello, if have an asp.net web page with a detailsview. This detailsview uses a sqldatasource connecting to a sql server 2005 database with a select statement simliar to this one: SELECT...
0
2396
by: gritbaby | last post by:
I have a SQL statement that keeps giving me this error: Error converting data type nvarchar to numeric. My select statement is the following: SELECT cast(Table.StringValue as numeric(4))...
0
2767
by: Adele | last post by:
Please help, I'm new to SQL and I use a script to import data and when I tried importing data tonight it gave me "error converting data type nvarchar to float". I have no idea what this error...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.