Wednesday, March 28, 2012

Passing Multiple GUIDs

Trying to build a report that will return information on many
contacts.
SELECT ContactExtensionBase.ContactId, ContactBase.LastName,
FROM ContactExtensionBase INNER JOIN
ContactBase ON ContactExtensionBase.ContactId = ContactBase.ContactId
WHERE (ContactBase.ContactId = @.cid)
where @.cid is the guid's
But with it like this i can't pass more than one guid into the
statement.Try using the "IN" clause so your WHERE statement looks like:
WHERE ContactBase.ContactId IN(@.cid)
If your parameter is set to accept multiple values then this will retrun ALL
values you select.
Michael
"flowk1337@.gmail.com" wrote:
> Trying to build a report that will return information on many
> contacts.
> SELECT ContactExtensionBase.ContactId, ContactBase.LastName,
> FROM ContactExtensionBase INNER JOIN
> ContactBase ON ContactExtensionBase.ContactId => ContactBase.ContactId
> WHERE (ContactBase.ContactId = @.cid)
>
> where @.cid is the guid's
>
> But with it like this i can't pass more than one guid into the
> statement.
>|||On Apr 27, 4:02 pm, Michael C <Michael C...@.discussions.microsoft.com>
wrote:
> Try using the "IN" clause so your WHERE statement looks like:
> WHERE ContactBase.ContactId IN(@.cid)
> If your parameter is set to accept multiple values then this will retrun ALL
> values you select.
> Michael
>
> "flowk1...@.gmail.com" wrote:
> > Trying to build a report that will return information on many
> > contacts.
> > SELECT ContactExtensionBase.ContactId, ContactBase.LastName,
> > FROM ContactExtensionBase INNER JOIN
> > ContactBase ON ContactExtensionBase.ContactId => > ContactBase.ContactId
> > WHERE (ContactBase.ContactId = @.cid)
> > where @.cid is the guid's
> > But with it like this i can't pass more than one guid into the
> > statement.- Hide quoted text -
> - Show quoted text -
I've already tried that actually. It gives an error that a I can't
convert from a guid to a string.|||Is the convertion error a matter of Collation? If so you may want to try and
COLLATE your join statement. I just can't see why a guid couldn't convert to
a string.
INNER JOIN
ContactBase ON ContactExtensionBase.ContactId COLLATE
SQL_Latin1_General_CP1_CI_AS = ContactBase.ContactId
have you tried to CAST or CONVERT the guid?
"flowk1337@.gmail.com" wrote:
> On Apr 27, 4:02 pm, Michael C <Michael C...@.discussions.microsoft.com>
> wrote:
> > Try using the "IN" clause so your WHERE statement looks like:
> >
> > WHERE ContactBase.ContactId IN(@.cid)
> >
> > If your parameter is set to accept multiple values then this will retrun ALL
> > values you select.
> >
> > Michael
> >
> >
> >
> > "flowk1...@.gmail.com" wrote:
> > > Trying to build a report that will return information on many
> > > contacts.
> >
> > > SELECT ContactExtensionBase.ContactId, ContactBase.LastName,
> > > FROM ContactExtensionBase INNER JOIN
> > > ContactBase ON ContactExtensionBase.ContactId => > > ContactBase.ContactId
> > > WHERE (ContactBase.ContactId = @.cid)
> >
> > > where @.cid is the guid's
> >
> > > But with it like this i can't pass more than one guid into the
> > > statement.- Hide quoted text -
> >
> > - Show quoted text -
> I've already tried that actually. It gives an error that a I can't
> convert from a guid to a string.
>|||On Apr 27, 5:56 pm, Michael C <Micha...@.discussions.microsoft.com>
wrote:
> Is the convertion error a matter of Collation? If so you may want to try and
> COLLATE your join statement. I just can't see why a guid couldn't convert to
> a string.
> INNER JOIN
> ContactBase ON ContactExtensionBase.ContactId COLLATE
> SQL_Latin1_General_CP1_CI_AS => ContactBase.ContactId
> have you tried to CAST or CONVERT the guid?
>
> "flowk1...@.gmail.com" wrote:
> > On Apr 27, 4:02 pm, Michael C <Michael C...@.discussions.microsoft.com>
> > wrote:
> > > Try using the "IN" clause so your WHERE statement looks like:
> > > WHERE ContactBase.ContactId IN(@.cid)
> > > If your parameter is set to accept multiple values then this will retrun ALL
> > > values you select.
> > > Michael
> > > "flowk1...@.gmail.com" wrote:
> > > > Trying to build a report that will return information on many
> > > > contacts.
> > > > SELECT ContactExtensionBase.ContactId, ContactBase.LastName,
> > > > FROM ContactExtensionBase INNER JOIN
> > > > ContactBase ON ContactExtensionBase.ContactId => > > > ContactBase.ContactId
> > > > WHERE (ContactBase.ContactId = @.cid)
> > > > where @.cid is the guid's
> > > > But with it like this i can't pass more than one guid into the
> > > > statement.- Hide quoted text -
> > > - Show quoted text -
> > I've already tried that actually. It gives an error that a I can't
> > convert from a guid to a string.- Hide quoted text -
> - Show quoted text -
I found out how to fix my problem. Thanks for your help Michael.
I created a stored procedure with the following:
DECLARE @.GUIDV VARCHAR(7000)
SELECT @.GUIDV = '''' + REPLACE(@.GUIDS , ',', '''' + ',' + '''')
+ ''''
EXECUTE('SELECT ContactExtensionBase.ContactId,
ContactExtensionBase.New_DLNumber, ContactBase.LastName,
ContactBase.MiddleName, ContactBase.FirstName, ContactBase.BirthDate,
ContactBase.MobilePhone, ContactBase.Pager, ContactBase.Telephone1,
ContactBase.StateCode,ContactExtensionBase.New_ReferralName,
ContactBase.Telephone2, ContactBase.Telephone3 FROM
ContactExtensionBase INNER JOIN
ContactBase ON ContactExtensionBase.ContactId =ContactBase.ContactId WHERE ContactId IN (' + @.GUIDV + ')')

No comments:

Post a Comment