Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

CAST Command
I am using MS-Access as a front end for my MS-SQL DB. I have a sql view that
uses the following:

SELECT     TOP 100 PERCENT RECID, PATNUMBER AS [PAT #], SVCCODE AS [
Service
Code], QTY, PROF_CHRGS AS [Pro Fee's'], AMOUNT,
BILLDATE AS [Bill Date], CHKAMT AS [Check Amt], PSDATE
AS [Service Date], POSTDATE AS [Post Date], TRNSCODE AS [T Code]
,
TRLR AS [T Code Desc],  SUBSTRING(CAST(SVCCO
DE AS
varchar), 1, 4) AS [Dept #]
FROM         dbo.PAT_Transactions
ORDER BY PATNUMBER, SVCCODE

My problem is the cast command. Will this sql view works and cast the
SVCCODE field into a varchar, I need to cast the reseult of  this,
 SUBSTRING(CAST(SVCCO
DE AS varchar), 1, 4) AS [Dept #], back in to a deci
mal
format. I am dropping this view onto a form and need to link to a field on
the form that is in decimal format.

The only way I could get this to work was to create another view, based on
the one above, and cast the [Dept #] field back into the decimal format.
 Is
there any better way to do this? Can I nest the Cast command?

Hope this makes sense.

Thanks in advance.

Mike
m charney at dunlap hospital dot org





Report this thread to moderator Post Follow-up to this message
Old Post
Mike
10-27-05 02:25 PM


Re: CAST Command
Like this:

 CAST(SUBSTRING(CAST(
svccod AS VARCHAR), 1, 4) AS DECIMAL(4,0))

--
David Portas
SQL Server MVP
--

"Mike" <noway@forgetit.com> wrote in message
news:qns6f.1047$jV2.300@newssvr17.news.prodigy.com...
>I am using MS-Access as a front end for my MS-SQL DB. I have a sql view
>that uses the following:
>
> SELECT     TOP 100 PERCENT RECID, PATNUMBER AS [PAT #], SVCCODE AS
> [Service Code], QTY, PROF_CHRGS AS [Pro Fee's'], AMOUNT,
>                      BILLDATE AS [Bill Date], CHKAMT AS [Check Amt
],
> PSDATE AS [Service Date], POSTDATE AS [Post Date], TRNSCODE AS 	
1;T Code],
>                      TRLR AS [T Code Desc],  SUBSTRING(CAST(SVCCO
DE AS
> varchar), 1, 4) AS [Dept #]
> FROM         dbo.PAT_Transactions
> ORDER BY PATNUMBER, SVCCODE
>
> My problem is the cast command. Will this sql view works and cast the
> SVCCODE field into a varchar, I need to cast the reseult of  this,
>  SUBSTRING(CAST(SVCCO
DE AS varchar), 1, 4) AS [Dept #], back in to a
> decimal format. I am dropping this view onto a form and need to link to a
> field on the form that is in decimal format.
>
> The only way I could get this to work was to create another view, based on
> the one above, and cast the [Dept #] field back into the decimal forma
t.
> Is there any better way to do this? Can I nest the Cast command?
>
> Hope this makes sense.
>
> Thanks in advance.
>
> Mike
> m charney at dunlap hospital dot org
>
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
David Portas
10-27-05 02:25 PM


Re: CAST Command
Mike (noway@forgetit.com)  writes:
> My problem is the cast command. Will this sql view works and cast the
> SVCCODE field into a varchar, I need to cast the reseult of  this,
>  SUBSTRING(CAST(SVCCO
DE AS varchar), 1, 4) AS [Dept #], back in to a
> decimal format. I am dropping this view onto a form and need to link to
> a field on the form that is in decimal format.
>
> The only way I could get this to work was to create another view, based
> on the one above, and cast the [Dept #] field back into the decimal
> format. Is there any better way to do this? Can I nest the Cast
> command?

Yes, you can nest:

 CAST(SUBSTRING(CAST(
SVCCODE AS varchar), 1, 4) AS decimal(p, s))




--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp


Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
10-27-05 02:25 PM


Re: CAST Command
Thanks!!


"David Portas" < REMOVE_BEFORE_REPLYI
NG_dportas@acm.org> wrote in message
 news:GtydncJkzuT17Mf
eRVnyjQ@giganews.com...
> Like this:
>
>  CAST(SUBSTRING(CAST(
svccod AS VARCHAR), 1, 4) AS DECIMAL(4,0))
>
> --
> David Portas
> SQL Server MVP
> --
>
> "Mike" <noway@forgetit.com> wrote in message
> news:qns6f.1047$jV2.300@newssvr17.news.prodigy.com... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Mike
10-27-05 02:25 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 03:28 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006