Solved

String Manipulation in SQL Server

Posted on 2009-07-16
3
241 Views
Last Modified: 2012-05-07
In reference to the code below, I am trying to find the GroupDescription 'Test: New Members 07/09/2009'.  The reason the @strDate variable was introduced was to allow for different dates to be entered.

When I run the query below however it returns no results yet when I run for the literal Group Description of  'Test: New Members 07/09/2009' it returns one row.

Can you help me correct this.
declare @studyID int

declare @studyGroupID int

declare @strDate varchar
 

/** Set studyID **/

set @studyID = 7

set @strDate = '07/09/2009' 
 

select @studyGroupID = StudyGroupID

from StudyGroups (nolock)

where GroupDescription = 'Test: New Members ' + @strDate

and StudyID = @studyID

Open in new window

0
Comment
Question by:onaled777
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24868864
>declare @strDate varchar
must be
declare @strDate varchar(20)
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24868868
explanation:
declare @strDate varchar
is the same as
declare @strDate varchar(1)
0
 

Author Comment

by:onaled777
ID: 24868891
Ahh Thank you!  I understand completely and it works.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Troubleshooting Methodology - steps 3 36
email the result out from a T-SQL queries 29 63
default constraint within a function 3 38
the whoisactive update 12 39
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now