Solved

String Manipulation in SQL Server

Posted on 2009-07-16
3
247 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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