ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   MID function and SQL Query (https://www.excelbanter.com/excel-programming/360119-mid-function-sql-query.html)

Soniya[_4_]

MID function and SQL Query
 
Hello!

Is it possible to use MID fiunction in SQL Query?

Or is there any other way to get it done..
StrSQL = " SELECT " & _
" j.Accno, SUM(j.db)DR, SUM(j.cr)CR, Month(j.Trdate)Month,
LEFT(j.tktno,4)ARL"
I would like to get "MID(j.Accno, 5, 3)Loc"

three charecters from Accno starting fifth character.

Thanks


AA2e72E

MID function and SQL Query
 
Use SUBSTRING instead of MID (same syntax)

PS:
instead of

SUM(j.db)DR

write

SUM(j.db) AS DR

makes t he SQL more readable and closer to the SQL conventions.


"Soniya" wrote:

Hello!

Is it possible to use MID fiunction in SQL Query?

Or is there any other way to get it done..
StrSQL = " SELECT " & _
" j.Accno, SUM(j.db)DR, SUM(j.cr)CR, Month(j.Trdate)Month,
LEFT(j.tktno,4)ARL"
I would like to get "MID(j.Accno, 5, 3)Loc"

three charecters from Accno starting fifth character.

Thanks



AA2e72E

MID function and SQL Query
 

I assumed you are using SQL Server. For Oracle, use SUBSTR. The Excel/Access
drivers can use MID.





All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com