Go Back   Rhinocerus > Newsgroup > Newsgroup comp.databases.* > Newsgroup comp.databases.ms-sqlserver

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 10-22-2005, 02:53 PM
Mike
Guest
 
Posts: n/a
Default 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(SVCCODE 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(SVCCODE 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?

Hope this makes sense.

Thanks in advance.

Mike
m charney at dunlap hospital dot org




Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 10-22-2005, 05:06 PM
David Portas
Guest
 
Posts: n/a
Default 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 [T Code],
> TRLR AS [T Code Desc], SUBSTRING(CAST(SVCCODE 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(SVCCODE 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?
>
> Hope this makes sense.
>
> Thanks in advance.
>
> Mike
> m charney at dunlap hospital dot org
>
>
>
>



Reply With Quote
  #3 (permalink)  
Old 10-22-2005, 05:08 PM
Erland Sommarskog
Guest
 
Posts: n/a
Default 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(SVCCODE 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/techinf...2000/books.asp

Reply With Quote
  #4 (permalink)  
Old 10-22-2005, 06:13 PM
Mike
Guest
 
Posts: n/a
Default Re: CAST Command

Thanks!!


"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message
news:GtydncJkzuT17MfeRVnyjQ@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 ...
>>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(SVCCODE 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(SVCCODE 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?
>>
>> Hope this makes sense.
>>
>> Thanks in advance.
>>
>> Mike
>> m charney at dunlap hospital dot org
>>
>>
>>
>>

>
>



Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to execute a DOS command without the command window Alan Churchill Newsgroup comp.soft-sys.sas 1 02-27-2008 06:44 AM
Re: FTP ing files using X command Jim Groeneveld Newsgroup comp.soft-sys.sas 2 09-27-2007 11:05 PM



All times are GMT. The time now is 05:54 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.