Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
One of my tables column contain the following type of data.

Room No
G111
1234
2342


Here the first letter indicates the floor no.

Kindly let me know which datatype to be used to store this kind of data..

I have tried varchar and nvarchar...but both of them not working..

Thank you..
Posted

In varchar(MAX) you can save any type of data (text ,number & special characters )
 
Share this answer
 
Comments
2012programmer 24-Nov-13 5:47am    
But, the problem here is, I am importing data from an MS-Excel file. I am able to insert the data from sql server mangement studio, but I am unable to import it from excel, bcoz of this data typ issue..
Jawad Ahmed Tanoli 24-Nov-13 5:58am    
Befor inserting into sql table check through debug what is the value of Room No in Query..
Jawad Ahmed Tanoli 24-Nov-13 6:10am    
to check
set allow null for RoomNo in table may be there is no value of RoomNo in Query.
2012programmer 24-Nov-13 6:23am    
the table is already exist, and I am using Import wizard of SQL server management studio, I am able to import it, but If the "roomno." column data is not starting with "G" then it is taking "NULL"(instead of no.1234)..
Note Solution 1 from Harsh Oswal is correct. This is not an alternative solution but additional information in response to subsequent comments

When importing from excel, if the table doesn't already exist, then SQL will attempt to work out what the column type should be based on the first row of data. If that row is numeric then you will hit a problem when you get to rows beginning with 'G'.

Ways around this ...

a) Define the table schema first and import to that table (rather than allowing SQL to create the table during the import)
OR
b) Ensure that the first row in the excel database contains textual data in that column (not recommended)
OR
c) Do data transformations as part of the import - there was a wizard for DTS imports in VS200-2005, there's bound to be one in the later versions.
 
Share this answer
 
Comments
2012programmer 24-Nov-13 6:22am    
the table is already exist, and I am using Import wizard of SQL server management studio, I am able to import it, but If the "roomno." column data is not starting with "G" then it is taking "NULL"(instead of no.1234)..
CHill60 24-Nov-13 6:35am    
Have you defined the column type in Excel as Text or left it as General?
2012programmer 24-Nov-13 7:00am    
yes I have defined as "Text"...still it is not working..
CHill60 24-Nov-13 7:37am    
I digging around some old notes as I hit this same problem a couple of years ago. Can't promise anything but I am going to have a look
2012programmer 24-Nov-13 7:46am    
Thanks alot for your help..appreciated your help...
if i understood it correctly you can use general datatype in excel
 
Share this answer
 
Comments
2012programmer 25-Nov-13 0:33am    
Yeah, I have tried with General datatype and Text data type also...
agent_kruger 25-Nov-13 5:17am    
general datatype accepts all type of data inputs please try again?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900