humer2000
asked on
Counting how many characters per columns (database field)
Hi
I have an access database with lot's of memo fields and text fields
I would like to migrate to SQL
I need a method that gives me the number of character i am actually using in each of my access database field so that i set correctly my varchars in SQL
thx
I have an access database with lot's of memo fields and text fields
I would like to migrate to SQL
I need a method that gives me the number of character i am actually using in each of my access database field so that i set correctly my varchars in SQL
thx
from sql try to get the max length
SELECT MAX(Len(myMemoField)) FROM myTable
SELECT MAX(Len(myMemoField)) FROM myTable
ASKER
sorry i am new to this
i need an automated way that writes on the screen the number of characters used per field / table
i need an automated way that writes on the screen the number of characters used per field / table
Hi
I think you are after something like this
<%
Set DataConn = Server.CreateObject("ADODB .Connectio n")
DataConn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\inetpub\ww wroot\asp\ db\employe es.mdb;Uid =Admin;Pwd =;"
set RS = server.createobject("ADODB .recordset ")
RS.Open "SELECT * FROM tblemployees", DataConn
FOR i=0 to RS.Fields.Count-1
response.write "NAME=" & RS.Fields(i).Name
response.write "<BR>SIZE=" & RS.Fields(RS.Fields(i).Nam e).defined size
response.write "<BR><BR>"
NEXT
RS.Close
DataConn.Close
set RS = Nothing
set DataConn = Nothing
%>
cheers
Len
I think you are after something like this
<%
Set DataConn = Server.CreateObject("ADODB
DataConn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\inetpub\ww
set RS = server.createobject("ADODB
RS.Open "SELECT * FROM tblemployees", DataConn
FOR i=0 to RS.Fields.Count-1
response.write "NAME=" & RS.Fields(i).Name
response.write "<BR>SIZE=" & RS.Fields(RS.Fields(i).Nam
response.write "<BR><BR>"
NEXT
RS.Close
DataConn.Close
set RS = Nothing
set DataConn = Nothing
%>
cheers
Len
also
FOR i=0 to RS.Fields.Count-1
response.write "NAME=" & RS.Fields(i).Name
response.write "<BR>SIZE=" & RS.Fields(RS.Fields(i).Nam e).defined size
response.write "<BR>Type=" & RS.Fields(RS.Fields(i).Nam e).type
response.write "<BR><BR>"
NEXT
you should then be able to work out the Name, datatype & size for your new SQL Server Field
cheers
Len
FOR i=0 to RS.Fields.Count-1
response.write "NAME=" & RS.Fields(i).Name
response.write "<BR>SIZE=" & RS.Fields(RS.Fields(i).Nam
response.write "<BR>Type=" & RS.Fields(RS.Fields(i).Nam
response.write "<BR><BR>"
NEXT
you should then be able to work out the Name, datatype & size for your new SQL Server Field
cheers
Len
ASKER
it does not give me the result i need
it gives the following :
NAME=cname
SIZE=255
Type=202
the cname field is a text field (type 202) and it supports 255 characters
but it does not tell me how many characters ar occupied or left ??
this is what i need for my SQL migration
it gives the following :
NAME=cname
SIZE=255
Type=202
the cname field is a text field (type 202) and it supports 255 characters
but it does not tell me how many characters ar occupied or left ??
this is what i need for my SQL migration
DTS-Export data(even without data).
Source as u r mS-Access
Destn as S-SQL server
And finish migration.
Why to worry lenght of field before hand.
DTS is there to take care.
After generate MS-SQL script and trim it.
ASKER
because i have lot's of fields and whilevarchars in SQL cannot exceed 8064 charatcers and while i cannot use the text or ntext type
i need to set my varchars correctly
ie, if all my cname requires maximum 24 charcters ten i set my varchar to 25 rather then fixing it blindly to 50
DTS is not ok for me, i have already tried it
i need to set my varchars correctly
ie, if all my cname requires maximum 24 charcters ten i set my varchar to 25 rather then fixing it blindly to 50
DTS is not ok for me, i have already tried it
If you use a combination of mine & nubeks solution you will e able to get what you need, I don't have time to fully code this at the moment but
do something like
FOR i=0 to RS.Fields.Count-1
response.write "NAME=" & RS.Fields(i).Name
response.write "<BR>SIZE=" & RS.Fields(RS.Fields(i).Nam e).defined size
response.write "<BR>Type=" & RS.Fields(RS.Fields(i).Nam e).type
For each row in RS ' set up a counter
maxlength = 0
length = row(RS.Fields(i).Name)
if length > maxlength then
maxlength =length
end if
Loop
response.write "<BR>maxlength of field=" & maxlength
response.write "<BR><BR>"
NEXT
(not the most effiicient, but as its a one off)
you will now have your field length, the maximum length of any field in that row, and you can calculate any other value you want
cheers
Len
do something like
FOR i=0 to RS.Fields.Count-1
response.write "NAME=" & RS.Fields(i).Name
response.write "<BR>SIZE=" & RS.Fields(RS.Fields(i).Nam
response.write "<BR>Type=" & RS.Fields(RS.Fields(i).Nam
For each row in RS ' set up a counter
maxlength = 0
length = row(RS.Fields(i).Name)
if length > maxlength then
maxlength =length
end if
Loop
response.write "<BR>maxlength of field=" & maxlength
response.write "<BR><BR>"
NEXT
(not the most effiicient, but as its a one off)
you will now have your field length, the maximum length of any field in that row, and you can calculate any other value you want
cheers
Len
ASKER
not working
i am getting this error
Microsoft VBScript compilation error '800a040e'
'loop' without 'do'
/csasp_db_countchar.asp, line 22
Loop
^
i am getting this error
Microsoft VBScript compilation error '800a040e'
'loop' without 'do'
/csasp_db_countchar.asp, line 22
Loop
^
That was just to give you the idea
For irow = 0 to RS.rowcount -1
maxlength = 0
length = len(row(RS.Fields(irow).Na me))
if length > maxlength then
maxlength =length
end if
next
For irow = 0 to RS.rowcount -1
maxlength = 0
length = len(row(RS.Fields(irow).Na
if length > maxlength then
maxlength =length
end if
next
ASKER
i am new to this and with your code errors, i guess i am too far from solution or even having an idea
you new code generates the following error
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'rowcount'
/csasp_db_countchar.asp, line 16
you new code generates the following error
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'rowcount'
/csasp_db_countchar.asp, line 16
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I hurried when i posted your answer as ACCEPTED
but in fact it's not resolved
i am not getting any error but the results obtained are not accurate
ie , it says for example
cdescription
SIZE= 536870910
Type= 203
longest entry in this field is 128 chars long
when i check my table
i have records with 2966 characters
and also when it says
specialoffer
SIZE= 100
Type= 202
longest entry in this field is 0 chars long
After checking my table this fields contains a message of 86 characters
what's the problem
but in fact it's not resolved
i am not getting any error but the results obtained are not accurate
ie , it says for example
cdescription
SIZE= 536870910
Type= 203
longest entry in this field is 128 chars long
when i check my table
i have records with 2966 characters
and also when it says
specialoffer
SIZE= 100
Type= 202
longest entry in this field is 0 chars long
After checking my table this fields contains a message of 86 characters
what's the problem
oopps sorry, should be
RS.movefirst
maxlength = 0
do While not RS.EOF
RS.movefirst
maxlength = 0
do While not RS.EOF
ASKER
great,
it works great
thank you
it works great
thank you
mLength = Len(SR("myMemoField"))