?
Solved

String Manipulation in SQL Server

Posted on 2009-07-16
3
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Expert Comment

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

762 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