MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old July 17th, 2008, 08:19 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Substring and Variable Help

One more question, then I'm done honestly. I need a query that does four things.
First Name = Frank
Last Name = Leppar
User ID = 300503

I need a fourth field that grabs the f.i. of first name, f.i. of last name, makes them both lower case, and then combines it with the student id:

eq: fl300503

Not hard right? I apologize on this one but I have no idea where to even get started on this. Again this is on a PHP site so I'm sure that will help.

NimirRamon who has already helped me out so much on these forums, posted this formula:
Code:
LOWER(SUBSTRING(0,1,[First Name]) + LOWER(SUBSTRING(0,1,[Last Name]) + [User ID]


He also stated it may not be exactly right, but at least I understand where to go with it. The problem is Im using a PHP page and all I do is grab the data from the previous text fields and input them into the database - so where should I post this query and what else would I have to do in order to get everything working?

Reply With Quote
  #17  
Old July 17th, 2008, 09:25 AM
f'lar's Avatar
f'lar f'lar is offline
Senior WeyrLeader
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 3,892 f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 5 Days 9 h 11 m 26 sec
Reputation Power: 788
Send a message via Google Talk to f'lar
First of all, that's not a query. It's just an excerpt from a query. Also, it is wrong. It's odd, but unlike many other languages SQL Server SQL strings are 1-indexed. I'll leave it as an exercise to you to apply that nugget- it's the best way for you to learn.

I'm no PHP expert, so I can't help you use the sql in php unless you give me more to go on from that side.
__________________
Primary Forums: .Net Development, MS-SQL, C Programming
VB.Net: It's not your father's Visual Basic.

[Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

Reply With Quote
  #18  
Old July 17th, 2008, 10:19 AM
NimirRamon NimirRamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 21 NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 17 h 27 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by f'lar
First of all, that's not a query. It's just an excerpt from a query. Also, it is wrong. It's odd, but unlike many other languages SQL Server SQL strings are 1-indexed. I'll leave it as an exercise to you to apply that nugget- it's the best way for you to learn.

I'm no PHP expert, so I can't help you use the sql in php unless you give me more to go on from that side.



Yeah I just gave an SQL excerpt for the chunk he was having difficulty with, really is more use in a simple update thinking about it.

Gah, I'd forgotten about it being 1-indexed (more fool me), I always default to 'traditional' indexing out of habit.

fleppar,

I think I misunderstood your initial requirements (or was in too much of a state to think properly), you could use PHPs string functions to do the lower casing, substringing and concatenation. Something like
PHP Code:
 $code strtolower(substr($fname,0,1)) . strtolower(substr($lname,0,1)) . $userid


Then you could use '$code' in the insert

Again apologies for any/all mistakes in the above, the logic is sound in my head, but Im running off a rather dodgy memory here.

Reply With Quote
  #19  
Old July 17th, 2008, 10:38 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by NimirRamon
I think I misunderstood your initial requirements (or was in too much of a state to think properly), you could use PHPs string functions to do the lower casing, substringing and concatenation. Something like
PHP Code:
 $code strtolower(substr($fname,0,1)) . strtolower(substr($lname,0,1)) . $userid


Then you could use '$code' in the insert

Again apologies for any/all mistakes in the above, the logic is sound in my head, but Im running off a rather dodgy memory here.


I just spoke with someone and we worked it out and got one that works - lemme quote what we came up with.

PHP Code:
 $final strtolower(substr($a01)) . strtolower(substr($b01)) . $c


hah exact same thing Ramon! I just based it off of the older equation you started me out with, so it's basically the same thing. I guess I could be worried about efficiency and make it:

PHP Code:
 $final strtolower(substr($a01) . substr($b01)) . $c


Something about math and "Simplify this equation" involved there. Either way - thanks a lot for all the help everyone. This has to be the one of the best, if not the best community for new developers and advanced ones alike.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Update All Records in a Row - Query Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT