iSTORYA.NET

Go Back   iSTORYA.NET > Technology > Software & Games > Programming
: :

Register FAQ Members List Calendar Mark Forums Read

Programming :: Programming related discussions ::

Reply
LinkBack Thread Tools
  #1  
Old 09-08-2008, 05:57 PM
Junior Member
tynum is offline
tynum's Avatar
Join Date: Jul 2008
Posts: 146
Default HELP! Conditional Statements in MYSQL

mga bro... naa ko'y gusto i query sa database that requires some conditions.. ang problema kay d ko kamao unsaon pag gamit ug conditions sa MYSQL... mao ni ako query:

select script.script_id, if(script.script_id == and script_error.script_id then return 'YES' else return 'NO') as ERROR from script, script_error

TABLES:

script ( script_id )
script_error ( script_error_id, script_id )

unsaon ni mga bro... kahibaw ko saup ako query peru d ko kahibaw unsaon para ma sakto... gusto ko na if naay pareha ug script_id between sa script ug script_error tables kay YES ang value na i return... else NO... tabang... lamat daan....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 09-08-2008, 07:33 PM
Junior Member
cold_fusion is offline
Join Date: Aug 2005
Gender: Male
Posts: 492
Default

Use the iif() function.

select script.script_id,
iif(script.script_id = script_error.script_id, 'YES', 'NO') as ERROR
from script, script_error

Does the two tables in your select statements needs to be joined?
If not the resulting set will be very large.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 09-09-2008, 01:00 PM
Junior Member
tynum is offline
tynum's Avatar
Join Date: Jul 2008
Posts: 146
Default

MR. COLD FUSION.... ur the man... hahah... lamat kaau bai ha.... peru ask lang ko ha... unsay advantage kung mag join ka?? weak jud kaau ko anang JOIN statements bro.... la pa kaau ko kasabot ana... ang simple join ra jud ako nasabtan ug maau... bsag nag basa nku about anang LEFT JOIN, RIGHT JOIN... d kaau nku pa grasp ang idea.... pwede pa tudlu?? in vernakular?? ahha.. or pwede sad kanang mu gamit ka ug mga words na dali ra masabtan.... hahaha... lamat jud kaau bro.. daku kaau ka ug tabang...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 09-10-2008, 03:35 PM
Junior Member
cold_fusion is offline
Join Date: Aug 2005
Gender: Male
Posts: 492
Default

It's difficult to explain.
Joins are used with tables that are normalized.
Read first about it here Database normalization - Wikipedia, the free encyclopedia .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 09-19-2008, 05:30 PM
Junior Member
tynum is offline
tynum's Avatar
Join Date: Jul 2008
Posts: 146
Default

HELP again at sql queries...

Quote:
PROBLEM:

select code from scripts where script_id = 00001;

//if code has a length of 200 characters....
gusto lang unta nku makuha na characters sa code kay 50 characters lang....

unsaon ni nku pag magic sa sql...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 09-19-2008, 05:43 PM
Junior Member
MarkCuering is offline
Join Date: Aug 2008
Posts: 360
Default

why not use LEN or LENGTH functions? depending in your platform like MySQL, Oracle, PostGres then use WHERE clause...?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 09-19-2008, 06:11 PM
Junior Member
ben77 is offline
ben77's Avatar
Join Date: Aug 2008
Posts: 225
Default

bro..

try daw adto na dauga sa imong form.... lets say if ang script_id=00001
dapat unta ang i return sa code mga 1000 ang iyang length....

im just assuming na imo gamit vb.net .... if ever... adto na lang dauga didto sa form....

gamit na lang ka ug mga built in functions....

if ever dili .... pasensya... hehehehehe


bitaw... try lang na ang return value nga gikuha nato sa database adto na lang na sa front end
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 09-19-2008, 09:30 PM
Junior Member
tynum is offline
tynum's Avatar
Join Date: Jul 2008
Posts: 146
Default

ok na mga bro... na magic na nku ang SQL statements... here is my magic.... hhahaha...

select substring(code,1,50) as LimitedCharCode from scripts where script_id = 00001;

gamit ra nku ang substring function....

syntax: substring(string, beginning offset, ending offset)
NOTE: if you want to start at the beginning, beginning offset should be one (1) kay i think index zero(0) does not exist... tried using zero and there was no output... tried using one and my magic worked.. hahah...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 09-19-2008, 09:40 PM
Junior Member
tynum is offline
tynum's Avatar
Join Date: Jul 2008
Posts: 146
Default

Quote:
Originally Posted by ben77 View Post
bro..

try daw adto na dauga sa imong form.... lets say if ang script_id=00001
dapat unta ang i return sa code mga 1000 ang iyang length....

im just assuming na imo gamit vb.net .... if ever... adto na lang dauga didto sa form....

gamit na lang ka ug mga built in functions....

if ever dili .... pasensya... hehehehehe


bitaw... try lang na ang return value nga gikuha nato sa database adto na lang na sa front end


lamat sa idea bro.. peru mas nindot jud bro kung daugon nmu sa SQL... kay mas lesser ang code lines na i process... so mas paspas mu compile imo program... so kung ma dala pa gani ug magic sa SQL.. magic-kon jud... peru d gani... go to d last resort... hehehe...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10  
Old 09-21-2008, 09:43 PM
Junior Member
ben77 is offline
ben77's Avatar
Join Date: Aug 2008
Posts: 225
Default

hehehehe....


bitaw sad...


try na nako pod ang imo gamit na substring...


thanks for the tip... magamit ra nya na nako...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11  
Old 09-22-2008, 09:42 AM
Junior Member
ingkiang is offline
ingkiang's Avatar
Join Date: Jan 2006
Posts: 297
Send a message via Yahoo to ingkiang
Default

nice2x...heheh...try sad ni nko if naa bani sa postgres
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12  
Old 09-23-2008, 01:10 PM
Junior Member
ben77 is offline
ben77's Avatar
Join Date: Aug 2008
Posts: 225
Default

Mysql String Manipulations....

got it from the net...


Name Description
ASCII() Returns numeric value of left-most character
BIN() Returns a string representation of the argument
BIT_LENGTH() Returns length of argument in bits
CHAR_LENGTH() Returns number of characters in argument
CHAR() Returns the character for each integer passed
CHARACTER_LENGTH() The same as CHAR_LENGTH()
CONCAT_WS() Returns concatenate with separator
CONCAT() Returns concatenated string
CONV() Converts numbers between different number bases
ELT() Returns string at index number
<=> NULL-safe equal to
= Equal
EXPORT_SET() Returns a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string
FIELD() Returns the index (position) of the first argument in the subsequent arguments
FIND_IN_SET() Returns the index position of the first argument within the second argument
FORMAT() Returns a number formatted to specified number of decimal places
>= Greater than or equal
> Greater than
HEX() Returns a string representation of a hex value
INSERT() Insert a substring at the specified position up to the specified number of characters
INSTR() Returns the index of the first occurrence of substring
IS NULL NULL value test
IS Test a value against a boolean
LCASE() The same as LOWER()
LEFT() Returns the leftmost number of characters as specified
LENGTH() Returns the length of a string in bytes
<= Less than or equal
< Less than
LIKE Simple pattern matching
LOAD_FILE() Load the named file
LOCATE() Returns the position of the first occurrence of substring
LOWER() Returns the argument in lowercase
LPAD() Returns the string argument, left-padded with the specified string
LTRIM() Removes leading spaces
MAKE_SET() Returns a set of comma-separated strings that have the corresponding bit in bits set
MID() Returns a substring starting from the specified position
!=, <> Not equal
NOT LIKE Negation of simple pattern matching
NOT REGEXP Negation of REGEXP
OCT() Returns a string representation of the octal argument
OCTET_LENGTH() The same as LENGTH()
ORD() If the leftmost character of the argument is a multi-byte character, returns the code for that character
POSITION() The same as LOCATE()
QUOTE() Escape the argument for use in an SQL statement
REGEXP Pattern matching using regular expressions
REPEAT() Repeat a string the specified number of times
REPLACE() Replace occurrences of a specified string
REVERSE() Reverse the characters in a string
RIGHT() Returns the specified rightmost number of characters
RLIKE The same as REGEXP
RPAD() Append string the specified number of times
RTRIM() Removes trailing spaces
SOUNDEX() Returns a soundex string (an alphanumeric string representing the phonetic representation of the word. Useful for finding words that sound similar)
SOUNDS LIKE() Compares sounds
SPACE() Returns a string of the specified number of spaces
STRCMP() Compares two strings
SUBSTRING_INDEX() Returns a substring from a string before the specified number of occurrences of the delimiter
SUBSTRING(), SUBSTR() Returns the substring as specified
TRIM() Removes leading and trailing spaces
UCASE() The same as UPPER()
UNHEX()() Converts each pair of hexadecimal digits to a character
UPPER() Converts to uppercase
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13  
Old 09-23-2008, 09:45 PM
Junior Member
tynum is offline
tynum's Avatar
Join Date: Jul 2008
Posts: 146
Default

WOW.... u really did your research ben77... pasalamat ta ni ben77... tungud niya naa na ta references bout sql functions... lamat bro... this would really come in handy...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14  
Old 09-23-2008, 11:07 PM
Junior Member
MarkCuering is offline
Join Date: Aug 2008
Posts: 360
Default

tagay naa....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15  
Old 09-28-2008, 12:30 AM
Junior Member
ben77 is offline
ben77's Avatar
Join Date: Aug 2008
Posts: 225
Default

daghang salamat... =)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump