| Author |
Topic |
|
2011SQL
Starting Member
12 Posts |
Posted - 2011-06-08 : 10:59:25
|
| Hello SQLTeam,I have a table with this following information:DocId110959011095911109592110959311095941109595110959611095971109500011095001110950021109500311095004110950051109500611095007110950081109500911095000110950001000101109500010001111095000100012110950001000131109500010001411095000100015110950001000161109500010001711095000100018777778577777867777787777778877777897777790777779177777927777771777777277777737777774I have a textbox search for DocIdI have a checkbox for only 7 digitsI have a checkbox for 8 digitsI have a checkbox for 14 digitsI have a checkbox for all digitswhen I type this number 11095 in textbox, it will display numbers :Results110959011095911109592110959311095941109595110959611095971109500011095001110950021109500311095004110950051109500611095007110950081109500911095000110950001000101109500010001111095000100012110950001000131109500010001411095000100015110950001000161109500010001711095000100018With textbox search : 11095, If I checked box for only 7 digits I would like to display the results of 7 digits from the value search I specified in the textbox:Results11095901109591110959211095931109594110959511095961109597With textbox search : 11095, If I checked box for only 8 digits I would like to display the results of 8 digits from the value search I specified in the textbox:Results1109500011095001110950021109500311095004110950051109500611095007110950081109500911095000With textbox search : 11095, If I checked box for only 14 digits I would like to display the results of 14 digits from the value search I specified in the textboxResults110950001000101109500010001111095000100012110950001000131109500010001411095000100015110950001000161109500010001711095000100018With textbox search : 11095, If I checked box for only All digits I would like to display the results of all digits from the value search I specified in the textboxResults110959011095911109592110959311095941109595110959611095971109500011095001110950021109500311095004110950051109500611095007110950081109500911095000110950001000101109500010001111095000100012110950001000131109500010001411095000100015110950001000161109500010001711095000100018What is the correct sql query syntax?SELECT SUBSTR(Doc_ID, 7) From ABC WHERE DOC_ID = ‘ “ & textBoxSearch & “ ‘SELECT CONVERT(varchar(7), doc_id(1,7) From ABCmaybe none above is correct.I hope you could help me on this. Your help is very appreciated. Thank you |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-08 : 11:54:01
|
| what have you tried?If you don't have the passion to help people, you have no passion |
 |
|
|
2011SQL
Starting Member
12 Posts |
Posted - 2011-06-08 : 12:03:17
|
| Thanks for reading my post.I have been trying but unsuccefully.See this line of Sql query: SELECT doc_id , abbrev convert(varchar(2),datepart(mm,date)) + '/' + convert(varchar(2),datepart(dd,date)) + '/' + convert(varchar(4),datepart(yyyy,date)) , FROM ABC WHERE doc_id not like '%[^0-9]% ORDER BY cast(doc_id as integer)Thanks |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-08 : 12:06:22
|
| sure. what is your query doing? do you understand what the query you posted is doing?If you don't have the passion to help people, you have no passion |
 |
|
|
2011SQL
Starting Member
12 Posts |
Posted - 2011-06-08 : 12:28:51
|
| Yes, I do understand. After run that query I posted, is not correct. Gave me error : The conversion of the varchar value '9999999999' overflowed an int column. Maximum integer value exceeded.I hope you could help me to find the right SQL Query that display only 7 digits when checked box... so on...See my VB.net programmingDim rx As Regex Dim m As Match = Match.Empty Dim CharFlag As Boolean 'check for valid entries that conform to regular expressions: If chk7digits.Checked Then rx = New Regex("^\d{7}$") CharFlag = True 'always set to pass Else CharFlag = False End If 'if the entry is in valid form: If m.Success And CharFlag = True Then 'initialize sorting: Session("SortExpression") = String.Empty Session("SortOrder") = String.Empty 'get the data and load the grid: DataFill() Else 'if the entry is not valid: ShowAlert("Not 7 digits found.")end ifDatafill()SQL QuerySELECT doc_id, convert(varchar(2),datepart(mm,date)) + '/' + convert(varchar(2),datepart(dd,date)) + '/'+ convert(varchar(4),datepart(yyyy,date)) ,FROM ABC WHERE doc_id LIKE '" & txtEntryNumber.Text & "%' ORDER BY cast(doc_id as integer) |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-08 : 13:08:06
|
| I would be happy to help you. but even better I would be happy to help you understand tsql programming. so are you working with SSIS or TSQL? what is up with the vb.net code?every time you are posting you put a different sql query which one are you currently using?If you don't have the passion to help people, you have no passion |
 |
|
|
2011SQL
Starting Member
12 Posts |
Posted - 2011-06-08 : 13:40:35
|
| Yosiasz,To be honest I understand very well the TSQL Programming. The reason of VB.Net code is because I am Visual Basic.Net programmer, and I am doing a Data search project with SQL Database with millions and millions of data. I am sorry the SQL queries I post because I was testing... I really appreciate if you could help me. Thanks. |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-08 : 14:08:21
|
please try thisdeclare @docs table(docid bigint)declare @parser intdeclare @DocPrefix nvarchar(255)insert into @docsSELECT 1109590UNIONSELECT 1109591UNIONSELECT 1109592UNIONSELECT 1109593UNIONSELECT 1109594UNIONSELECT 1109595UNIONSELECT 1109596UNIONSELECT 1109597UNIONSELECT 11095000UNIONSELECT 11095001UNIONSELECT 11095002UNIONSELECT 11095003UNIONSELECT 11095004UNIONSELECT 11095005UNIONSELECT 11095006UNIONSELECT 11095007UNIONSELECT 11095008UNIONSELECT 11095009UNIONSELECT 11095000UNIONSELECT 11095000100010UNIONSELECT 11095000100011UNIONSELECT 11095000100012UNIONSELECT 11095000100013UNIONSELECT 11095000100014UNIONSELECT 11095000100015UNIONSELECT 11095000100016UNIONSELECT 11095000100017UNIONSELECT 11095000100018UNIONSELECT 7777785UNIONSELECT 7777786UNIONSELECT 7777787UNIONSELECT 7777788UNIONSELECT 7777789UNIONSELECT 7777790UNIONSELECT 7777791UNIONSELECT 7777792UNIONSELECT 7777771UNIONSELECT 7777772UNIONSELECT 7777773UNIONSELECT 7777774SET @DocPrefix = '11095'SET @parser = 7 SELECT docid From @Docs WHERE LEN(docid) = @parser AND LEFT(CAST(docid as nvarchar(max)),LEN(@DocPrefix)) LIKE @DocPrefix If you don't have the passion to help people, you have no passion |
 |
|
|
2011SQL
Starting Member
12 Posts |
Posted - 2011-06-08 : 14:35:18
|
| I tried and test your SQL Query. It was very interesting, nice and it worked so well.Since I have this following SQL Query, please see it:SELECT doc_ID [Document] FROM ABC WHERE doc_ID LIKE '11095%' ORDER BY cast(doc_ID as integer)What should I put on my sql query from your SQL QueryShould I put this way:SELECT doc_ID [Document] FROM ABC WHERE doc_ID LIKE '11095%' AND LEN(doc_ID) LIKE 7 AND LEFT(CAST(doc_ID as integer(max))ORDER BY cast(doc_ID as integer)Thanks |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-08 : 15:50:37
|
you want to make it dynamic right? so you cannot put LIKE '11095%'You need to create a sproc and pass it the two variables @parser, @DocPrefixSince you understand very well the TSQL Programming that should be a breezeSELECT doc_ID [Document] FROM ABC WHERE LEN(docid) = @parser AND LEFT(CAST(docid as nvarchar(max)),LEN(@DocPrefix)) LIKE @DocPrefix If you don't have the passion to help people, you have no passion |
 |
|
|
2011SQL
Starting Member
12 Posts |
Posted - 2011-06-08 : 17:54:11
|
| I got it. Thank you so much for your attention and help.Thanks again, yosiasz |
 |
|
|
|