Solved

String Manipulation in SQL Server

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

18 Experts available now in Live!

Get 1:1 Help Now