Solved

String Manipulation in SQL Server

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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 …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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