Re: CONVERT
From: Adam Machanic (amachanic_at_air-worldwide.nospamallowed.com)
Date: 03/23/04
- Next message: Tom Moreau: "Re: Top x Percent for each group"
- Previous message: Hotmail: "Need "On Change Of" aggregate"
- In reply to: Jaco: "CONVERT"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 23 Mar 2004 10:09:38 -0500
First of all, please read this article which will show you how to get rid of
the dynamic SQL using a table-valued UDF:
http://www.algonet.se/~sommar/arrays-in-sql.html
Second, you have not posted DDL and therefore it is impossible to know what
datatypes are doing what in this query. I'm also wondering what
GeographyName is doing internally -- could that be your culprit? If you
want to get rid of the nulls, use COALESCE -- look it up in BOL.
"Jaco" <anonymous@discussions.microsoft.com> wrote in message
news:275D67DA-795F-4759-B7C3-71018D03A728@microsoft.com...
> Hello
>
> I am trying to run this SP. The problem is that if one of my fields have
null values it returns with an error 'Implicit conversion from data type
text to nvarchar is not allowed. Use the CONVERT function to run this
query' -
> any help please.
>
>
>
>
>
>
>
>
>
> CREATE PROCEDURE qfm_DiaryFormPMSchedule
>
> @Parms nvarchar(4000)
>
> AS
>
> Declare @QUERY nvarChar(4000)
> set @QUERY = N'Select [Site] = (dbo.GeographyName((Select
Inventory.GeographyID from Geography,Inventory where
Geography.GeographyID=Inventory.GeographyID and
Inventory.InventoryID=InventoryPM.InventoryID),1,NULL)), '
> set @QUERY = @QUERY + N'[InventoryID] as [Asset No], '
> set @QUERY = @QUERY + N'(Select Model from Model where ModelID in (select
ModelID from Inventory where InventoryPM.InventoryID=Inventory.InventoryID))
as Model, '
> set @QUERY = @QUERY + N'(Select EquipmentReference from Inventory where
Inventory.InventoryID=InventoryPM.InventoryID) as [Equipment Ref], '
> set @QUERY = @QUERY + N'(Select Serial from Inventory where
Inventory.InventoryID=InventoryPM.InventoryID) as [Serial], '
> set @QUERY = @QUERY + N'[PMDescription] as [PM Description], '
> set @QUERY = @QUERY + N'[PMStartDate] as [Start Date], '
> set @QUERY = @QUERY + N'[EndDate] as [End Date], '
> set @QUERY = @QUERY + N'[LastPMDate] as [Last Inspection], '
> set @QUERY = @QUERY + N'[PMFrequency] as Frequency, '
> set @QUERY = @QUERY + N'[DurationDays] as [Duration (Days)], '
> set @QUERY = @QUERY + N'[DurationHours] as [Duration (Hours)], '
> set @QUERY = @QUERY + N'[DurationMins] as [Duration (Mins)], '
> set @QUERY = @QUERY + N'(Select Name from Agent where
InventoryPM.AgentID=Agent.AgentID) as Contractor, '
> set @QUERY = @QUERY + N'(Select Name from Priority where
InventoryPM.PriorityID=Priority.PriorityID) as Priority, '
> set @QUERY = @QUERY + N'[Instructions] as [Instructions], '
> set @QUERY = @QUERY + N'[Remarks] as [Remarks], '
> set @QUERY = @QUERY + N'InventoryID as [NavigationID] '
> set @QUERY = @QUERY + N'FROM InventoryPM '
> set @QUERY = @QUERY + N'WHERE InventoryPMID IN (' + @Parms + ')'
>
> --print @QUERY
>
> Exec sp_executesql @QUERY
> GO
>
- Next message: Tom Moreau: "Re: Top x Percent for each group"
- Previous message: Hotmail: "Need "On Change Of" aggregate"
- In reply to: Jaco: "CONVERT"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|