Results 1 to 3 of 3

Thread: T-sql syntaxis for sql server

  1. #1
    JohnDW is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Location
    Antwerp, Belgium
    Posts
    58
    Reputation
    15

    T-sql syntaxis for sql server


    I have an t-sql syntax in sqlservermanagement , but
    it doesn't work. The purpose is that when I enter a value (a number that exists out of 2 numbers (dossiernumberjaar and dossiervolgnumber) the record comes:
    The follwing code works but then I have to give 2 values (dossiernummer jaar and dossiervolgnummer):
    Code:
    SELECT
     TblDossiers.DossierNummerJaar,TblDossiers.DossierVolgNummer,
    tblDossiers.Klantnummer, tblDossiers.Bedrag, tblDossiers.DateUitgeschreven, 
    tblDossiers.Uitbetaald, tblDossiers.Uitbetaald, Klant.Naamvoornaam
    From tblDossiers Inner Join Klant On tblDossiers.Klantnummer = Klant.Klantnummer
    where (DossierNummerJaar = 12 and DossierVolgNummer = 233)
    It must be something like this but it doesn't work:
    Code:
    where Cast(DossierNummerJaar As int) + 'R' + CAST(DossierVolgNummer As int) = 12233
    Can someone help me?
    John

  2. #2
    Herman is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    448
    Reputation
    346
    The query seems fine, except you forgot table identifiers on the WHERE clause, although they shouldn't be necessary unless the same column name is used in the two tables. In any case, learn to use aliases, it clears up a lot of extra typing. All you really need to do is provide the two parameters through the SqlCommand object. Also the query as is looks for BOTH DossierNummerJaar and DossierVolgNummer. Replace the AND with a OR and you should be fine.

    SELECT d.DossierNummerJaar, d.DossierVolgNummer, d.Klantnummer, d.Bedrag, d.DateUitgeschreven, d.Uitbetaald, d.Uitbetaald, k.Naamvoornaam
    FROM tblDossiers d
    INNER JOIN Klant k ON d.Klantnummer = k.Klantnummer
    WHERE d.DossierNummerJaar = @DossierNummerJaar OR d.DossierVolgNummer = @DossierVolgNummer

  3. #3
    JohnDW is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Location
    Antwerp, Belgium
    Posts
    58
    Reputation
    15
    Ok Herman, THise sytax works fine!
    But suppose the user wants to add the whole number.
    For example if @DossierNummerJaar = 12 and @DossierVolgNummer = 233,
    he adds '12233'. ANd the query is lookin in the fields DossierNummerJaar and DossierVOlgNummer .
    How I use this in a query:

    something like:

    Code:
    SELECT d.DossierNummerJaar, d.DossierVolgNummer, d.Klantnummer, d.Bedrag, d.DateUitgeschreven, d.Uitbetaald, d.Uitbetaald, k.Naamvoornaam FROM tblDossiers d INNER JOIN Klant k ON d.Klantnummer = k.Klantnummer WHERE (d.DossierNummerJaar + '' + d.DossierVolgNummer) = 12232
    



    I'm lookin for this query syntaxis so I can use it in my stored procedure.
    The query above doesn't work.
    Can you help me with that?

    Txs,

    John

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking